*Slide 5--slight variation with separate filename statement; *Use tab-delimited text files fall8.txt, fall9.txt, fall10.txt from website; filename cohort08 ('d:\stat 541\fall8.txt' 'd:\stat 541\fall9.txt' 'd:\stat 541\fall10.txt'); data all; infile cohort08 dlm='09'X missover dsd truncover; input major :$38. degree :$16. class :$9. cltotgpa gender $ nobs; run; /* Alternatively, in SAS Studio, upload data files into folder and then: */ filename cohort08 ("/home/davidhitchcock/sasuser.v94/stat541/Fall8.txt" "/home/davidhitchcock/sasuser.v94/stat541/Fall9.txt" "/home/davidhitchcock/sasuser.v94/stat541/Fall10.txt"); data all; infile cohort08 dlm='09'X missover dsd truncover; input major :$38. degree :$16. class :$9. cltotgpa gender $ nobs; run; proc print data=all; run; *Slide 13; data combined; do i=8,9,10; fname='d:\stat 541\fall'||compress(put(i,2.)||'.txt'); do until(lastobs); infile temp filevar=fname end=lastobs dlm='09'X missover dsd truncover; input major :$38. degree :$16. class :$9. cltotgpa gender $ nobs; output; end; end; stop; run; /* Alternatively, in SAS Studio, upload data files into folder and then: */ data combined; do i=8,9,10; fname="/home/davidhitchcock/sasuser.v94/stat541/Fall"||compress(put(i,2.)||".txt"); do until(lastobs); infile temp filevar=fname end=lastobs dlm='09'X missover dsd truncover; input major :$38. degree :$16. class :$9. cltotgpa gender $ nobs; output; end; end; stop; run; proc print data=combined; run; * Example with month() and today(); data one; now=today(); thismth=month(today()); prevmth=month(today()) - 1; earlmth=month(today()) - 4; /* causes problem when run in early month of year */ run; proc print data=one; format now date9.; run; *Slide 19; data a; input date date7.; wkday=weekday(date); current_month=intnx('month',date,0); last_month=intnx('month',date,-1); next_bimonthly=intnx('month2.1',date,1); current_week=intnx('week',date,0); two_weeks_from_now=intnx('week2',date,1); current_quarter=intnx('quarter',date,0); reset_current_quarter=intnx('quarter.2',date,0); next_year=intnx('year',date,1); next_year_same=intnx('year',date,1,'same'); next_month_same=intnx('month',date,1,'same'); next_month_begin=intnx('month',date,1,'beginning'); next_month_end=intnx('month',date,1,'end'); datalines; 02jan11 09jan11 11jan11 12jan11 02feb11 08feb11 14feb11 01mar11 02mar11 28mar11 31mar11 03apr11 01jan12 07jan12 14jan12 21jan12 01feb12 08feb12 15feb12 22feb12 29feb12 03mar12 04mar12 27mar12 31mar12 ; run; proc print; format date current_month last_month next_bimonthly current_week two_weeks_from_now current_quarter reset_current_quarter next_year next_year_same next_month_same next_month_begin next_month_end mmddyy9.; run; *Slide 23; *Create separate data sets by year; *We could work with these files, but the demo of force would not be interesting ; *since the three files come from a common file; data fall08 fall09 fall10; set combined; if _n_ le 3364 then output fall08; else if _n_ le 6728 then output fall09; else output fall10; run; *Import data sets--these files will have variables with different lengths and formats; proc import out=fall08 datafile="d:\stat 541\Fall 2008.xls" dbms=xls replace; sheet="Sheet1"; run; proc import out=fall09 datafile="d:\stat 541\Fall 2009.xls" dbms=xls replace; sheet="Sheet1"; run; proc import out=fall10 datafile="d:\stat 541\Fall 2010.xls" dbms=xls replace; sheet="Sheet1"; run; /* Alternatively, in SAS Studio, upload data files into folder and then: */ *Import data sets--these files will have variables with different lengths and formats; proc import out=fall08 datafile="/home/davidhitchcock/sasuser.v94/stat541/Fall 2008.xls" dbms=xls replace; sheet="Sheet1"; run; proc import out=fall09 datafile="/home/davidhitchcock/sasuser.v94/stat541/Fall 2009.xls" dbms=xls replace; sheet="Sheet1"; run; proc import out=fall10 datafile="/home/davidhitchcock/sasuser.v94/stat541/Fall 2010.xls" dbms=xls replace; sheet="Sheet1"; run; *Look for problems in merge; *Very few problems identified here; data falltwoyr; set fall08 fall09; run; *multiple problems identified here; proc append base=fall08 data=fall09; proc append base=falltwoyr data=fall10; run; *Identify issues with variables; proc contents data=falltwoyr; proc contents data=fall10; run; *Needed in Fall 2012, not Fall 2014; *Drop CLTOTGPA from FALL10 since it is problematic; data fall10nogpa (drop=cltotgpa); set fall10; run; *See Record 7855 for an example of truncation; proc append base=falltwoyr data=fall10 force; proc print data=falltwoyr (firstobs=7855 obs=7855); proc print data=fall10 (firstobs=1127 obs=1127); /* original record */ run; *Slide 25; *Set up a file containing the filenames; data a; input filename $22.; datalines; e:\stat 541\fall8.txt e:\stat 541\fall9.txt e:\stat 541\fall10.txt ; run; /* Alternatively, in SAS Studio, upload data files into folder and then: */ *Set up a file containing the filenames; data a; input filename $51.; datalines; /home/davidhitchcock/sasuser.v94/stat541/Fall8.txt /home/davidhitchcock/sasuser.v94/stat541/Fall9.txt /home/davidhitchcock/sasuser.v94/stat541/Fall10.txt ; run; data combined; set a; infile cohort08 filevar=filename end=lastfile dlm='09'X missover dsd truncover; do while(lastfile=0); input major :$38. degree :$16. class :$9. cltotgpa gender $ nobs; output; end; run;