You are on page 1of 25

Questions

1. How do I change default SAS System user profile folder in SAS 9.0? For example I want to set the wor!ing directory to c"#mysas. 2. How do I chec! syntax errors in my SAS program $efore I su$mit it? 3. How do I reorder %aria$les& position in a SAS data set? 4. How do I remo%e duplicate o$ser%ations from my data set? 5. I ha%e a huge data set. Is there a 'uic! way for me to sort my whole data out? 6. How do I replace missing %alues with the %aria$le mean in my data set? 7. How do I accumulate a numeric %aria$le to get a total amount (totfaminc) for each group (one household id per record)? 8. How do I create a uni'ue I* for my data set? 9. How do I count o$ser%ations per su$+ect in a data set? 10. How do I count words in SAS? 11. I ha%e a messy string %aria$le with people&s names and addresses. How do I correct them? 12. How do I add a mean %alue of a %aria$le $ac! to my original data set? 13. How do I add mean %alues and total count of a categorical %aria$le $ac! to my original data set? For example" mean %alues of height for Sex (female and male). 14. I ha%e a program that I closed and forgot to sa%e $ut I do ha%e a log file from when I ran it. ,an I ta!e the text from the log file and ma!e it a program again? 15. I want to sa%e hard dri%e space. How do I write a code to delete some or all temporary files once I do not need them any more? 16. I am using a %ery huge data set in SAS for windows. How do I minimi-e space re'uirements? 17. .hat is the difference $etween /ne0to01any and 1any0to0/ne 1atched 1erge in SAS? 18. I ha%e two data sets. I want to do a 1atched 1erge and output only consisting of %aria$les from $oth files.How do I do it? 19. I ha%e two data sets. How do I do a 1atched 1erge and output consisting of %aria$les in file2 $ut not in file3 or in file3 $ut not in file2 (id004 5 6 7)? 20. I ha%e two data sets. How do I do a 1atched 1erge and output consisting of %aria$les from master file (id002 3 8 4 5)? 21. I ha%e two large data sets. How do I do a 1atched 1erge and output consisting of %aria$les file2 $ut not infile3 (id004 5)? 22. How do I merge 20 data sets with a common %aria$le and the same prefix data name? For example" data2 todata20 with common %aria$le of I*. 23. I ha%e SAS and S9A9A $ut I do not ha%e Stat:9ransfer program in my computer. Is there any easy way for meto con%ert my SAS data set to S9A9A? 24. How do I rotate data from long format to wide format? 25. 1y string %aria$le 1;1/ contains two 'uotes (it&s &o!&). .hat should I do if I want to use an if:then statementto chec! the %alue of < (if 1;1/ = it&s &o!& then ...>)? 26. How do I use ?roc SQ@ to get mean(%ar) std(%ar) min(%ar) max(%ar) median(%ar) from a data set? 27. How do I create a data set with o$ser%ations =200 mean 0 and standard de%iation 2? 28. How do I randomly sample a certain proportion of o$ser%ations from a SAS dataset? For example 20A.

29. How do I create a summari-ed report without creating a new %aria$le? For example" I ha%e an AB; %aria$le and I want to generate a summari-ed report that shows the num$er of people in different groups. 30. Is there a simple way to indicate an integer range in SAS? 31. How do I !now what products in my computer are licensed? .hat is my site num$er and when will my SASexpire? 32. I ha%e a file that is an acti%ity $ased file for each person throughout the day. 9here is a start time and end time as well as a duration time that shows how many minutes they were doing the acti%ity. I need to create a file which has a 2440 o$ser%ation for each person for e%ery minute of the day. How do I create a time serial data? 33. How do I create a data set with a permanent %aria$le %alue la$el (permanent format)? 34. I ha%e +ust recei%ed a SAS data file (emp.sas7$dat) with a SAS format file (formats.sas7$cat). How do I use them? 35. How do I create a flat text file from a SAS data set? 36. How do I set /*S to sa%e my output in H91@ format $y default? 37. How do I sort the %alues of two related arrays? 38. I am using a large data set. How do I eliminate the output in the output window? 39. How can I change the orientation for printing in my SAS program? 40. I want to sa%e paper while printing. How can I change the font when printing my SAS code output file and log file? 41. How can I generate percentile ran!s using SAS? 42. How do I generate a directory file with total o$ser%ations total %aria$les file si-e and the last time the file was modified for a defined li$rary name? 43. How do I direct output a file from output window to a flat file? 44. How do I automatically output a single txt file that contains $oth @/B and @S9 files? 45. I want to sa%e paper when printing the output file $y s!ipping page $rea!s. .hat can I do? 46. I ha%e a character %aria$le with regulate time %alue li!e 02"00"00 pm and 09"00"03 am in my SAS data set. I want to order 9am earlier than 2pm. .hat should I do? 47. I ha%e a character %aria$le with regulate time %alue li!e 04"80"02 or 38"00"00 in my SAS data set. I want tocon%ert them to hours. How do I do that? 48. How do I con%ert a character date %alue to a SAS date %alue? 49. I ha%e a character %aria$le with mix regulate date %alue li!e 02mar99 02 mar 99 and 020mar0 2999. I want tocon%ert them to SAS date %alue. .hat should I do? 50. How do I create a categorical %aria$le using a %aria$le&s percentage? 51. I !eep getting an error message Cout of memoryC when I use proc fre' with two categorical %aria$les to try toget a fre' report. .hy and how do I a%oid this pro$lem? 52. I need to create a comma separated file (.cs%) from a SAS data what should I do?

ADS.;ES
2. Q" How do I change default SAS System user profile folder in SAS 9.0? For example I want to set the wor!ing directory to c"#mysas. A: The best way to do this is to change the -sasuse !a a"ete in the sas#9.c$g $i%e. &ust set this in sas#9.c$g $ o" you co"!ute and you a e eady to go.

-sasuse 'c:("ysas' 3. Q" How do I chec! syntax errors in my SAS program $efore I su$mit it? A: 1. Add ')!tion )bs*0+ ,o-e!%ace+' on the to! o$ you .A. ! og a" and sub"it you .A. ! og a". 2. /hec0 you 1og window and eset .yste" )!tions bac0 to ')bs*"a2+ -e!%ace+' i$ the e is not any e o s in you .A. ! og a". 3. .ub"it you .A. ! og a" again. 8. Q" How do I reorder %aria$les& position in a SAS data set? A: 3ou can add eithe 1ength o -etain state"ent be$o e a .et state"ent in a data ste!. 4o e2a"!%e: data a+ in!ut a1 b1 c1 a2 b2 c2 a3 b3 c3+ data%ines+ 123456789 + data b+ %ength a1-a3 3. b1-b3 3. c1-c3 3. + set a+ un+ data c+ etain a1-a3 b1-b3 c1-c3+ set a+ un+ 4. Q" How do I remo%e duplicate o$ser%ations from my data set? A: 1. 3ou can use 5 oc .o t with o!tion ,odu! to e"o#e du!%icate obse #ations $o a%% #a iab%es o with o!tion ,odu!6ey to e"o#e du!%icate obse #ations $o 7y 0ey #a iab%es on%y $ o" you data set. 2. 8u!out is a new o!tion in 5 oc .o t. 9t na"es a .A. data set that wi%% contain the du!%icate eco ds e%i"inated $ o" the data set. 3. 3ou can a%so use 49-.T. and 1A.T. #a iab%es in a data ste! to e"o#e du!%icate obse #ations. data te"!1+ in!ut id 2 y + ca ds + 1 20 1 1 20 1 1 20 2 2 20 3

3 20 4 + ! oc so t data*te"!1 out*te"!2 nodu!+ by id+ un+ ! oc ! int data*te"!2 + tit%e :no du!%icates $o a%% #a iab%es:+ un+ ! oc so t data*te"!1 out*te"!3 nodu!0ey du!out*d o!!ed+ by id+ un+ ! oc ! int data*te"!3 + tit%e :no du!%icate $o by #a iab%e on%y:+ un+ ! oc ! int data*d o!!ed+ tit%e :new data set 8 o!!ed %ists 2 obse #ations with du!%icate 0ey #a%ues we e de%eted $ o" the data set Te"!1:+ un+ ! oc so t data*te"!1+ by id+ un+ data nodu!+ set te"!1+ by id+ i$ $i st.id then out!ut+ un+ ! oc ! int data*nodu!+ un+ data nodu! du!+ set te"!1+ by id+ i$ $i st.id then out!ut nodu!+ e%se out!ut du!+ un+ ! oc ! int data*nodu!+ un+ ! oc ! int data*du!+ un+

5. Q" I ha%e a huge data set. Is there a 'uic! way for me to sort my whole data out? A: ;sua%%y< a gene a% u%e-o$-thu"b $o ca%cu%ating so t s!ace e=ui es th ee ti"es the s!ace o$ the dataset. 1. The Tagso t o!tion is #e y good on %a ge datasets whe e 0ey is s"a%%. 2. ;se the ,oe=ua%s o!tion on 5-)/ .)-T i$ you do not want to 0ee! that o de the sa"e as the obse #ations that we e in the in!ut data. 6. Q" How do I replace missing %alues with the %aria$le mean in my data set? A: The easiest way is to use 5 oc .tanda d with -e!%ace o!tion to e!%ace a%% "issing #a%ues with the #a iab%e "ean. 4o e2a"!%e: data aw + in!ut #a 1-#a 5+ data%ines+ 1.166 25277 35.88 45499 5 5 5 . 10 + ! oc standa d data* aw out* e!>"ean e!%ace+ #a #a 1-#a 5+ un+ )ut!ut: 1 5 1 6.0 6 2 5 2 7.0 7 3 5 3 8.0 8 4 5 4 9.0 9 5 5 5 7.5 10 7. Q" How do I accumulate a numeric %aria$le to get a total amount (totfaminc) for each group (one hhid per record)? A: 3ou can use 4i st. and 1ast. #a iab%es in a data ste! to do it. data test+ in!ut hhid !n $a"inc+ data%ines+ 1 1 30000 1 2 20000 130 2 1 50000 220 +

! oc so t+ by hhid+ un + data new+ set test+ by hhid+ i$ $i st.hhid then tot$a"inc*0+ tot$a"inc?$a"inc+ i$ %ast.hhid then out!ut+ d o! !n+ un+ )ut!ut: hhid !n $a"inc tot$a"inc 1 3 0 50000 2 2 0 50000 F. Q" How do I create a uni'ue I* for my data set? A: 3ou can eithe use .u" state"ent @id?1+A o syste" #a iab%e '>n>' to do so. data de"o+ id?1+ in!ut id B #1-#5+ ca ds + A 10 20 30 40 50 7 11 12 13 14 15 / 15 20 25 30 35 8 22 33 44 55 66 + data new+ set sashe%!.c%ass+ id*>n>+ un+ 9. Q" How do I count o$ser%ations per su$+ect in a data set? A: ;se .;C state"ent and 49-.T. #a iab%e to count obse #ations !e subDect. 4o e2a"!%e: data te"!+ in!ut id nu"+ data%ines+ 11 12 11 21

22 31 + ! oc so t data*te"!+ by id+ data te"!1+ set te"!+ by id+ count?1+ i$ $i st.id then count*1+ un+ ! oc so t+ by id descending count+ un+ data te"!2+ set te"!1+ by id+ etain totc+ i$ $i st.id then totc*count+ out!ut+ un+ ! oc ! int+ un+ )ut!ut: id nu" count totc 1 1 1 3 1 2 2 3 1 1 3 3 2 1 1 2 2 2 2 2 3 1 1 1 20. Q" How do I count words in SAS? A: ;se the $unction o$ count@ A in .A. #9 to si"!%y count the nu"be o$ sub-st ings that occu in a st ing. data a+ 2*'good good study< day day u!' y*count@2<:day:A+ un+ 22. Q" I ha%e a messy string %aria$le with people&s names and addresses. How do I correct them?

A: 9t:s #e y easy to do it with 5-)5/A.E $unction in .A. F9. 4o e2a"!%e: data ! o!e + in!ut na"e cha 20.+ na"e * ! o!case@na"eA+ data%ines+ De$$ -ust A"y %ee + ! oc ! int+ un+ 23. Q" How do I add a mean %alue of a %aria$le $ac! to my original data set? A: 1. ;se 5 oc Ceans to c eate a new data set to ho%d a "ean #a%ue $o the #a iab%e. 2. ;se a data ste! with two .ET state"ents to add a "ean #a%ue bac0 to you o igina% data set. 4o e2a"!%e: ! oc "eans data*sashe%!.c%ass+ #a height+ out!ut out*new "ean*a#g>height+ un+ data adda#g+ i$ >,> *1 then set new+ set sashe%!.c%ass + un+ 28. Q" How do I add mean %alues and total count of a categorical %aria$le $ac! to my original data set? For example" mean %alues of height for Sex (female and male). A: 1. .o t the data by .e2. 2. ;se 5 oc Ceans with 73 to c eate a new data set to ho%d a "ean and count #a%ues by .e2. 3. ;se a data ste! with CE-GE state"ents to "e ge the" by .e2. ! oc so t data*ye.c%ass+ by se2+ ! oc "eans data*ye.c%ass+ #a height+ by se2+ out!ut out*new "ean*a#g>height n *n>height+ un+ ! oc so t+ by se2+ un+ data adda#g+ "e ge sashe%!.c%ass new+ by se2+ d o! >ty!e> >$ e=>+

un+ )ut!ut: ,a"e &oyce 3eats .e Age Height Ieight Ieight height n>height 2 4 4 11 12 12 13 13 51.3 59.8 56.3 56.5 65.3 50.5 84.5 77.0 84.0 98.0 61.7500 61.7500 61.7500 61.7500 61.7500 8 8 8 8 8 8 8 8 8 11 11 11 11 11 11 11 11 11 11

1ouise 4 A%ice 4

7a ba a 4 /a o% &udy &anet Ca y 4 4 4 4

14 62.8 14 64.3 15 62.5 15 66.5 57.5 57.3 59.0

102.5 61.7500 90.0 61.7500

112.5 61.7500 112.0 85.0 83.0 99.5 61.7500 62.7636 62.7636 62.7636

Tho"as C 11 &a"es C 12 &ohn ye C 12

-obe t C 12 64.8 &e$$ ey C 13 A%$ ed Hen y 62.5

128.0 62.7636 84.0 112.5 102.5 1.0 62.7636 62.7636 62.7636 62.7636

C 14 69.0 C 14 63.5

Ii%%ia" C -ona%d C 5hi%i!

15 66.5 15 67.0

133.0 62.7636 1.0 62.7636

C 16 72.0

24. Q" I ha%e a program that I closed and forgot to sa%e $ut I do ha%e a log file from when I ran it. ,an I ta!e the text from the log file and ma!e it a program again?

A: 3es< 3ou can. 9n %og window< ho%d A1T< "o#e the cu so to you code and high%ight it. -ight c%ic0 and se%ect edit< then se%ect co!y. Go bac0 to .A. Edit Iindow and !aste it. 25. Q" I want to sa%e hard dri%e space. How do I write a code to delete some or all temporary files once I do not need them any more? A: 3ou can "anua%%y de%ete a%% te"!o a y $i%es $ o" 'Io 0' %ib a y. 3ou can a%so use the 8atasets ! ocedu e with the 8e%ete o .a#e state"ent to de%ete so"e o$ te"!o a y $i%es. The 6i%% o!tion wi%% de%ete a%% .A. $i%es i""ediate%y a$te you sub"it the state"ent. E2a"!%e: 1. 8e%ete a%% te"!o a y $i%es $ o" 'Io 0' %ib a y ! oc datasets %ib a y*wo 0 "e"ty!e*data 0i%%+ un+ =uit+ 2. 8e%ete so"e te"!o a y $i%es $ o" 'Io 0' %ib a y ! oc datasets %ib a y*wo 0 "e"ty!e*data+ de%ete test1 test2+ Jde%etes datasets test1 K test2 and 0ee!s the est+ =uit+ ! oc datasets %ib a y*wo 0 "e"ty!e*data+ sa#e test3+ Jsa#es test3 and de%etes the est+ =uit+ 26. Q" I am using a %ery huge data set in SAS for windows. How do I minimi-e space re'uirements? A: Ihen you a e wo 0ing with %a ge data sets< you can do the $o%%owing ste!s to educe s!ace e=ui e"ents. 1. .!%it huge data set into s"a%%e data sets. 2. /%ean u! you wo 0ing s!ace as "uch as !ossib%e at each ste!. 3. ;se dataset o!tions @0ee!* < d o!*A o state"ent @0ee!< d o!A to %i"it to on%y the #a iab%es needed. 4. ;se 94 state"ent o )7. * to %i"it the nu"be o$ obse #ations. 5. ;se IHE-E* o IHE-E o inde2 to o!ti"iLe the IHE-E e2! ession to %i"it the nu"be o$ obse #ations in a 5 oc .te! and 8ata .te!. 6. ;se %ength to %i"it the bytes o$ #a iab%es. 7. ;se >nu%%> dataset na"e when you don:t need to c eate a dataset. 8. /o"! ess dataset using syste" o!tions o dataset o!tions @/)C5-E..*yes o /)C5-E..*bina yA. 9. ;se .M1 to do "e ge< su""a y< so t etc. athe than a co"bination o$ 5 oc .te! and 8ata .te! with te"!o a y datasets. 27. Q" .hat is the difference $etween /ne0to01any and 1any0to0/ne 1atched 1erge in SAS? A: )ne-to-Cany "e ge is the sa"e as a Cany-to-)ne Catched Ce ge e2ce!t the o de o$ the

#a iab%es in the new data set is di$$e ent. 4o e2a"!%e: data d1+ in!ut stud B teache B+ data%ines+ 7a y.andy 7i%% .ue

E%%en .ue &ohn .ue + ! oc so t + by teache + un+ data d2+ in!ut teache B oo"+ data%ines+ .andy 101 .ue 103 + ! oc so t + by teache + un+ data co"bine1t2 + "e ge d1 d2 + by teache + un+ data co"bine2t1 + "e ge d2 d1+ by teache + un+ )ut!ut@"e ge d1 d2+A: stud teache oo" 7a y.andy 7i%% .ue 103 101 101 101

E%%en .ue &ohn .ue

)ut!ut@"e ge d2 d1+A: teache oo" stud .andy .ue .ue .ue 103 7a y 101 7i%% 101 E%%en 101 &ohn

2F. Q" I ha%e two data sets. I want to do a 1atched 1erge and output only consisting of o$ser%ations from $oth files. How do I do it? A: 9n .A.< the e is a 7oo%ean $%ag ca%%ed 9,* #a iab%e. 9t is used $o "atched "e ge to t ac0 and se%ect whichobse #ations in the data set $ o" the "e ge state"ent wi%% go to a new data set. data $i%e1+ in!ut id na"e B+ data%ines+ 1 &ohn 2 &oe 3 7i%% 4 7ob 5 .andy + ! oc so t data*$i%e1+ by id+ un+ data $i%e2+ in!ut id state B+ data%ines+ 1 C8 2 ,3 3 FA 6 ,& 7 ,/ + ! oc so t data*$i%e2+ by id+ un+ data in>both+ "e ge $i%e1@in*in$i%e1A $i%e2@in*in$i%e2A+ by id+

i$ in$i%e1* in$i%e2+ un+ )ut!ut: 1 &ohn C8 2 &oe ,3 3 7i%% FA 29. Q" I ha%e two data sets. How do I do a 1atched 1erge and output consisting of o$ser%ations in file2 $ut not infile3 or in file3 $ut not in file2 (id004 5 6 7)? A: data in>both+ "e ge $i%e1@in*in$i%e1A $i%e2@in*in$i%e2A+ by id+ i$ in$i%e1 ne in$i%e2+ un+ )ut!ut: 4 7ob 5 .andy 6 ,& 7 ,/ 30. Q" I ha%e two data sets. How do I do a 1atched 1erge and output consisting of o$ser%ations from master file (id002 3 8 4 5)? A: data in>both+ "e ge $i%e1@in*aA $i%e2+ by id+ i$ a+ un+ ! oc ! int+ un+ )ut!ut: 1 Dohn C8 2 Doe ,3 3 bi%% FA 4 bob 5 sandy 32. Q" I ha%e two large data sets. How do I do a 1atched 1erge and output consisting of %aria$les file2 $ut not infile3 (id004 5)? A: 7oth 8ata .te! with Ce ge state"ent and 5 oc .M1 a e )6< but 5 oc .M1 has a highe e$$iciency to do it $o %a ge data set. data not>in>a+ "e ge $i%e1@in*2A $i%e2@in*yA+

by id+ i$ not y+ un+ ! oc s=%+ c eate tab%e not>in>a as se%ect id $ o" $i%e1 e2ce!t se%ect id $ o" $i%e2 + =uit+ 33. Q" How do I merge 20 data sets with a common %aria$le and the same prefix data name? For example" data2to data20 with common %aria$le of I*. A: The best way is to use a "ac o. o!tions "! int+ data data1+ in!ut id 2+ data%ines+ 11 22 33 44 + data data2+ in!ut id y+ data%ines+ 15 26 37 48 + data data3+ in!ut id L+ data%ines+ 19 2 10 3 11 4 12 + .... N"ac o "y"e ge @nA+

8ata "e ged+ Ce ge Ndo i * 1 N to Kn+ dataKi Nend+ 7y id+ -un+ N"end+ N"y"e ge@10A 38. Q" I ha%e SAS and S9A9A $ut I do not ha%e Stat:9ransfer program in my computer. Is there any easy way for me to con%ert my SAS data set to S9A9A? A: 3es. Cethod1: The e is a .tata use -w itten @Ado-$i%eA co""and OusesasP c eated by 8 . 8an 7%anchette. The co""and uses .A. to un .A. "ac o sa#astata.sas and %oad the .A. dataset into .tata:s "e"o y i$ you ha#e .A. insta%%ed inyou co"!ute . The use can decide to sa#e the data as a .tata data set using .tata:s Osa#eP co""and a$te that. 4o e2a"!%e: 1. ;se .tata:s co""and 'ssc insta%%' to down%oad and insta%% it. ssc insta%% usesas 2. ;se 'usesas' co""and to %oads a .A. data set $ o" you co"!ute into .tata:s "e"o y. usesas using Oc:(data(you sasdat.sas7bdatP 3. .a#e you .tata data i$ needed. sa#e datna"e

Cethod2: 9n .A.< c eate a t ans!o t $o "at $i%e. %ibna"e out Q5)-T 'c:(data(c%ass.2!t'+ data out.c%ass+ set sashe%!.c%ass+ un+ 9n .TATA< use co""and '$dause' to ead the t ans!o t $o "at $i%e into .tata:s "e"o y: cd c:(data $dause c%ass sa#e c%ass 34. Q" How do I rotate a data from long format to wide format? A: -est uctu e data set $ o" %ong $o "at to wide $o "at with a ays. data 2+

in!ut tucaseid tu%ineno !e % ea #+ data%ines+ 1 1 100 200 2 1 300 400 2 2 500 600 3 1 700 800 3 2 900 1000 3 3 1100 1200 4 1 1300 1400 + ! oc so t+ by tucaseid + un+ data y + set 2+ by tucaseid + etain !e % 1-!e % 4 ea #1-ea #4 i+ a ay a y>!e % @4A !e % 1-!e % 4+ a ay a y>ea #@4A ea #1-ea #4+ i$ $i st.tucaseid then do+ do i * 1 to 4+ a y>!e % @iA*0+ a y>ea #@iA*0+ end+ i*1+ end+ a y>!e % @iA*!e % + a y>ea #@iA*ea #+ i*i?1+ i$ %ast.tucaseid then out!ut+ d o! !e % ea # i tu%ineno+ un+ )ut!ut: tucaseid !e % 1 !e % 2 !e % 3 !e % 4 ea #1 ea #2 ea #3 ea #4 1 2 3 100 300 700 0 500 900 0 0 200 0 0 400 800 0 600 0 0 0

1100 0

1000 1200 0

1300 0

1400 0

35. Q" 1y string %aria$le 1;1/ contains two 'uotes (it&s &o!&). .hat should I do if I want to use an if:then statement to chec! the %alue of < (if 1;1/ = it&s &o!& then ...>)? A: /hec0 the #a%ue o$ CEC) using i$Rthen state"ent as $o%%ows: i$ CEC) * 'it:s :o0:' then y*1+ 36. Q" How do I use ?roc SQ@ to get mean(%ar) std(%ar) min(%ar) max(%ar) median (%ar) from a data set? A: Cedian@A $unction is not a 'su""a y' $unction in 5-)/ .M1. 7ut it is !ossib%e $o you to ca%cu%ate CE89A, with "o e %abo Dob using 5-)/ .M1. data a+ in!ut age+ data%ines+ 1 2 3 4 6 + 5 oc s=%+ .e%ect "ean@ageA< std@ageA< "in@ageA< "a2@ageA $ o" a+ .e%ect a#g@"edianA as "edian $ o" @se%ect 2.age as "edian $ o" a as 2< a as y g ou! by 2.age ha#ing su"@sign@2.age-y.ageAA in @1<0<-1AA+ Muit+ 37. Q" How do I create a data set with o$ser%ations =200 mean 0 and standard de%iation 2? A: data one+ do i * 1 to 100+ nu" * 0 ? anno @1A J 1+ out!ut+ end+ un+ ! oc "eans data * one "ean stdde#+ #a nu"+ un+ 3F. Q" How do I randomly sample a certain proportion of o$ser%ations from a SAS dataset? For example 20A. A: 9n the 8ATA ste!< inc%ude the %ine to se%ect a!! o2i"ate%y 10N o$ the obse #ations $ o" the o igina% data.

i$ anuni@0AS*.1 + 3ou can a%so use 5 oc .u #eyse%ect to c eate a si"!%e ando" sa"!%ing siLe. 4o e2a"!%e< sa"!%ing siLe 10. ! oc su #eyse%ect data*sashe%!.c%ass "ethod*s s n*10 out*.a"!%e10+ un+ 39. Q" How do I create a summari-ed report without creating a new %aria$le? For example" I ha%e an AB; %aria$le and I want to generate a summari-ed report that shows the num$er of people in different groups. A: 1. / eate a use de$ined $o "at $o the g ou!. 2. 9n 5 oc 4 e=< when the $o "at is a!!%ied to a #a iab%e on the TA71E state"ent< the $o "atted #a%ue wi%% be used $o the dist ibution. 5 oc $o "at+ Fa%ue $"tnu" . * :"issing: 1ow -S0 * :negati#e: 0 * :Le o: 0 S- high * :!ositi#e:+ -un+ 5 oc $ e=+ #a se2+ $o "at se2 se2$"t.+ un+ 80. Q" Is there a simple way to indicate an integer range in SAS? A: 3es< in .A. #e sion9< 9, o!e ato acce!ts intege anges "o e easi%y than be$o e. 4o e2a"!%e: you can use 'age in @11< 13:19A' instead o$ 'i$ age *11 o 13 S* age S*19' 82. Q" How do I !now what products in my computer are licensed? .hat is my site num$er and when will my SASexpire? A: 5 oc setinit+ te%%s you what you ha#e cu ent%y #a%id %icenses and site nu"be < and de$ined ! oducts in you session. 5 oc setinit+ un + 83. Q" I ha%e a file that is an acti%ity $ased file for each person throughout the day. 9here is a start time and end time as well as a duration time that show how many minutes they were doing the acti%ity. I need to create a file which has a 2440 o$ser%ation for each person for e%ery minute of the day. Howdo I create a time serial data?

A: The e a e se#e a% ways to do it. 9$ you .TA-T T9CE and E,8 T9CE a e .A. ti"e #a%ues< you can easi%y c eate 'sta t"in' #a iab%e using 'sta tti"e' di#ided by 60 and c eate 'end"in' #a iab%e using 'endti"e' di#ided by 60< and then c eate you ti"e se ia% data. )the wise< you can Dust use du ation ti"e #a iab%e to do it. data a+ in!ut id acti#ity>code sta tti"e endti"e+ data%ines+ 1118 1 2 9 17 1 3 18 24 2119 2 5 10 18 2 3 19 24 + data b+ set a+ h s*sta tti"e+ do unti%@h s*endti"eA+ h s?1+ count*h s-sta tti"e+ out!ut+ end+ un+ Np 88. Q" How do I create a data set with permanent %aria$le %alue la$el (permanent format)? A. 1. / eate a !e "anent $o "at using o!tion o$ '%ib a y*! oDect' in ! oc $o "at state"ent. 2. ;se ')!tions 4CT.EA-/H * @! oDectA+' to te%% .A. whe e to %oo0 $o the $o "at. 3. Accesses a !e "anent $o "at using $o "at state"ent. RJ"y$o "at.sas -- / eating a !e "anent $o "atJR 1ibna"e ! oDect :/:(:+ ! oc $o "at %ib a y*! oDect+ #a%ue B se2$"t :C:*:"a%e: :4 :*:$e"a%e: + #a%ue age$"t 1-17 *:17 and unde : 18-high *:18 and u!: +

un+ RJ"ysas$i%e.sas--Accessing a !e "anent $o "atJR )!tions 4CT.EA-/H * @! oDectA+ RJTe%% .A. whe e to %oo0 $o the $o "at JR %ibna"e ! oDect :c:(:+ data ye.!e ">$o "at+ set sashe%!.c%ass+ $o "at se2 Bse2$"t. age age$"t.+ un+ ! oc ! int+ un+ 84. Q" I ha%e +ust recei%ed a SAS data file (emp.sas7$dat) with a SAS format file (formats.sas7$cat). How do I use them? A: .a#e both o$ the" in the sa"e di ecto y in you co"!ute . 4o e2a"!%e< /:(. I ite a .A. ! og a" as be%ow and sub"it it. %ibna"e "y%ib 'c:('+ %ibna"e %ib a y 'c:('+ o!tions $"tsea ch * "y%ib+ ! oc "eans data*"y%ib.auto+ un+ 85. Q" How do I create a flat text file from a SAS data set? A: 3ou can use a .tatRT ans$e ! og a" to con#e t it. 3ou can a%so use 5 ocu e @5 oc e2!o t and 5 oc ! inttoA o 4i%e and 5ut state"ents in a data ste! to c eate it. $i%ena"e awdat :c:(out!ut.t2t: + data >nu%%>+ set sashe%!.c%ass + $i%e awdat + !ut na"e age+ un + 86. Q" How do I set /*S to sa%e my output in H91@ format $y default? A: 3ou can go to .A. ! e$e ence sc een to eset settings a#ai%ab%e to te%% .A. to sa#e a%% 8ata ste! and 5 oc out!utin HTC1 $o "at. 1. /%ic0 the Too%s o!tion< 2. /%ic0 the )!tions o!tion< 3. /%ic0 the 5 e$e ences... o!tion< 4. /%ic0 the -esu%ts tab< 5. 4o HTC1 out!ut< chec0 the / eate HTC1 bo2.

87. Q" How do I sort the %alues of two related arrays? A: 3ou can eithe use 8o %oo! with two a ays o /A11 .)-T, to do it. data te"!+ 2*3 + y*1 + L*2 + #a%ue>2*100+ #a%ue>y*300+ #a%ue>L*200+ un + data b+ set te"!+ a ay a y1@3A 2 y L+ a ay a y2@3A #a%ue>2 #a%ue>y #a%ue>L+ "a2*0+ do i * 1 to 3+ i$ a y1@iA T "a2 then do+"a2* a y1@iA + "a2othe * a y2@iA + end+ e%se do+t*"a2+ a y1@i-1A*a y1@iA+a y1@iA*t+ tothe *"a2othe + a y2@i-1A*a y2@iA+ a y2@iA*tothe + end+ end+ 0ee! 2 y L #a%ue>2 #a%ue>y #a%ue>L+ un+ data so ta ay+ set te"!+ /A11 .)-T, @2< y< L< #a%ue>2< #a%ue>y< #a%ue>LA+ un+ 8F. Q" I am using a large data set. How do I eliminate the output in output window? A: Add the $o%%owing state"ent in you code to "a0e ',o out!ut destinations acti#e'. )8. %isting c%ose+ 89. Q" How can I change the orientation for printing in my SAS program? A: Add the $o%%ow co""and in you .A. ! og a" to cont o% the ! inte :s o ientation setting. d" :d%g! tsetu! o ient*%andsca!e nodis!%ay:+ 40. Q" I want to sa%e paper while printing. How can I change the font when printing my SAS code output file and log file? A. The de$au%t $ont $o ! inting .A. code< out!ut $i%e< and %og $i%e is 10. 3ou can use o!tion .3.5-9,T4),T to set it.

)5T9),. .3.5-9,T4),T*:.A. Conos!ace: 6+ ! oc ! int data*sashe%!.c%ass+ un+ 42. Q" How can I generate percentile ran!s using SAS? A: ! oc an0 g ou!s*100 out*dataset+ #a 2 y+ an0s ! #1 ! #2+ un+ 43. Q" How do I generate a directory file with total o$ser%ations total %aria$les file si-e and the last time the file was modified for a defined li$rary name? A: ;se ! oc datasets to chec0 in$o "ation o$ tota% obse #ations< tota% #a iab%es< $i%e siLe and the %ast ti"e the $i%e was "odi$ied $o a de$ined '%ib a y' $ o" %og window. ! oc datasets %ib a y*"y%ib "t*data detai%s+ un+ =uit+ ;se )8. to sa#e the" to a new data set: ods out!ut "e"be s*di >"y%ib+ ! oc datasets %ib a y*"y%ib "t*data detai%s+ un+ =uit+ ods out!ut c%ose+ 48. Q" How do I direct outputting a file from output window to a flat file? A: 3ou can use 5 oc 5 intto to auto"atica%%y oute out!ut to a $i%e. ! oc ! intto ! int*:c:(auto.%st: new+ .... un+ 44. Q" How do I automatically output a single txt file that contains $oth @/B and @S9 files? A: $i%ena"e ! oD1 :c:("ysas(out!ut(! oD1.t2t:+ ! oc ! intto %og* ! oD1 ! int* ! oD1 new+ Jbegging you ! og a" he eJR data test+ set sashe%!.c%ass+ ! oc eg+ "ode% weight * height+ un+ Jend you ! og a" he eJR

! oc ! intto+ un+ 45. Q" I want to sa%e paper when printing output file $y s!ipping page $rea!s. .hat can I do? A: To tu n o$$ the !age b ea0 setting $o " out!ut window< use syste" o!tions. To tu n o$$ the !age b ea0 set this o!tion..... o!tions $o "d%i"*: :+ a b%an0 To tu n !age b ea0s bac0 on o!tions $o "d%i"*::+ no b%an0 data new+ ti"e*'11:25'+ hou *scan@ti"e<1<:::A+ "inute*scan@ti"e<2<:::A+ sasti"e*h"s@hou <"inute<0A+ $o "at sasti"e ti"e5.+ un+ 46. Q" I ha%e a character %aria$le with regulate time %alue li!e 02"00"00 pm and 09"00"03 am in my SAS data set. I want to order 9am earlier than 2pm. .hat should I do? A: 3ou can use in!ut $unction with .A. ti"e $o "at to con#e t it to .A. ti"e #a%ue< and then so t by ascending. data a+ Jin!ut begin ti"e8.+ in!ut begin B 10.+ data%ines+ 01:00:00 a" 01:00:00 !" 09:00:02 a" 12:00:03 !" + data b+ set a+ newti"e*in!ut@begin< ti"e12.A+ ! oc so t+ by newti"e+ ! oc ! int+ un+ 47. Q" I ha%e a character %aria$le with regulate time %alue li!e 04"80"02 or 38"00"00 in my SAS data set. I want tocon%ert them to hours. How do I do that? A: 1. ;se ./A, $unction to get how "any hou s< "inutes and seconds $ o" you cha acte #a iab%e

2. ;se HC. $unction to con#e t the" to seconds 3. /on#e t seconds to hou s 4o e2a"!%e: data new+ ti"e*'04:30:01'+ hou *scan@ti"e<1<:::A+ "inute*scan@ti"e<2<:::A+ se*scan@ti"e<3<:::A+ sasti"e*h"s@hou <"inute<seA+ h 24*h"s@hou <"inute<seAR3600+ con#e t24*h"s@scan@ti"e<1<:::A<scan@ti"e<2<:::A<scan@ti"e<3<:::AAR3600+ un+ 4F. Q" How do I con%ert character date %alue to a SAS date %alue? A: 3ou can use in!ut $unction to do it. data one+ in!ut cha date B8. + data%ines+ 19600101 19591231 20000101 + data two+ set one+ sasdate*in!ut@cha date<yy""dd8.A+ un+ )ut!ut: cha date sasdate 19600101 0 19591231 -1 20000101 14610 49. Q" I ha%e a character %aria$le with mix regulate date %alue li!e 02mar99 02 mar 99 and 020mar0 2999. I wantto con%ert them to SAS date %alue. .hat should I do? A: 3ou can use in!ut $unction with .A. date $o "at to con#e t it to .A. date #a%ue. .A. data set. data aa+ in!ut U1 #a 1 B 20. + data%ines+ 01"a 99 01 "a 99

01-"a -1999 + data bb+ set aa+ statadate * in!ut@#a 1<date11.A + un+ 50. Q" How do I create a categorical %aria$le using a %aria$le&s percentage? A: 3ou can use 5 oc 4 e= to gene ate a #a iab%e ca%%ed 5E-/E,T< "e ge it bac0 to you o igina% data< and then c eate a catego ica% #a iab%e using #a iab%e 5E-/E,T. ! oc $ e= data*ye.c%ass+ tab%e ageRout*age$ e=@0ee!*age 5E-/E,TA+ un+ ! oc so t data*ye.c%ass+ by age+ ! oc so t data*age$ e=+ by age+ data a%%+ "e ge ye.c%ass@in*aA age$ e=+ by age+ i$ a+ 5E-/E,T*int@5E-/E,TA+ i$ 5E-/E,T T 20 then $ e=cat*1+ e%se $ e=cat*0+ un+ 52. Q. I !eep getting an error message Cout of memoryC when I use proc fre' with two categorical %aria$les to tryto get a fre' report. .hy and how do I a%oid this pro$lem? A: .A. sto es a%% o$ the #a%ue co"binations in "e"o y du ing ! ocessing when you use 5 oc 4 e=. Ihen the e a etoo "any %e#e%s o$ catego ica% #a iab%es they wi%% use u! "any "e"o ies esu%ting in the e o "essage 'out o$ "e"o y'. 9n o de to ! e#ent this e o < use 5 oc .o t with 7y state"ent and a%so inc%ude a 7y state"ent in you 5 oc 4 e=. 53. Q" I need to create a comma separated file (.cs%) from a SAS data what should I do? A: A =uic0 and easy way is using '8ata >nu%%>'. $i%ena"e out$i%e :c:(c%ass.cs#:+ data >nu%%>+ $i%e out$i%e+ set sashe%!.c%ass+ !ut @>a%%>A @:<:A+ un+

You might also like