data exercise1;
set snowy1;
if dpq020=. then depression=.;
else if dpq020= 1 then depression=1;
else if dpq020=2 then depression=1;
else if dpq020=3 then depression=1;
else if dpq020=0 then depression=0;
else if dpq020=7 then delete;
else if dpq030=9 then delete;
if PAQ635 =2 then walkbike=0;
else if PAQ635=1 then walkbike=1;
else if paq635=7 then delete;
else if paq635=9 then delete;
if paq635=. then delete;
if paq605=1 then vigorouswork=0;
else if paq605=2 then vigorouswork=1;
else if paq605=7 then delete;
else if paq605=9 then delete;
if paq605=. then delete;
if PAQ650 =2 then vigorousrec=0;
else if PAQ650=1 then vigorousrec=1;
else if PAQ650=7 then delete;
else if PAQ650=9 then delete;
if PAQ650=. then delete;
if paq620=1 then moderatework=0;
else if paq620=2 then moderatework=1;
else if paq620=7 then delete;
else if paq620=9 then delete;
if paq620=. then delete;
if PAQ665 =2 then moderaterec=0;
else if PAQ665=1 then moderaterec=1;
else if PAQ665=3 then delete;
else if PAQ665=7 then delete;
else if PAQ665=9 then delete;
if PAQ655=. then delete;
if ridageyr <=18 then delete;
rename ridageyr=age;
run;
label
Depression="feeling down, depressed, or hopelesss 0:no 1:yes";
Walkbike="do you walk or bicylce to work 0:no 1:yes";
vigorouswork= "vigorous work activity 0:no 1:yes";
vigorousrec= "vigorous recreational activities 0:no 1:yes";
moderatework="moderate work activity 0:no 1:yes";
moderaterec= "moderate recreational activities 0:no 1:yes";
proc contents data= exercise1;
run;
wondering why when I run this code, for each label statements it is saying: Statement is not valid or it is used out of proper order. (also I am extremely new to SAS/coding in general, first semester student)
label Depression="feeling down, depressed, or hopelesss 0:no 1:yes";
Walkbike="do you walk or bicylce to work 0:no 1:yes";
At the end of the first line, there is a semicolon which ends the the LABEL statement. Thus the next line is not part of the LABEL statement, and SAS doesn't recognize it as a valid statement.
@kclm87009 Please go back to your ORIGINAL post and modify the subject line to briefly describes the problem. From now on, please use meaningful Subject lines that briefly describes the problem, rather than something that indicates you need help. If everyone used "Help" or "I'm confused" or "SAS not working right", the forum would be difficult to use.
How many observations did you lose when you ran this code?
Did you actually intend to remove observations just because some values of what I would suspect are responses to survey questions were something like "don't know" or "refused"? (a guess, there are a number of survey writers that us 7 for "don't know" and 9 for "refused").
It may make more sense unless you really have a good reason for deleting entire responses to use something like:
if dpq020=. then depression=.; else if dpq020= 1 then depression=1; else if dpq020=2 then depression=1; else if dpq020=3 then depression=1; else if dpq020=0 then depression=0; else if dpq020=7 then depression=.; else if dpq030=9 then depression=.;
and similar for those 7 and 9 values, set analysis variable to missing.
Setting values to missing will mean that those are not used for analysis. When you actually remove an observation, which is what the DELETE statement does, then the entire thing is not available at all.
If you want to restrict part of your analysis later to where there are "valid" responses use a WHERE statement such as
Proc freq data=some dataset;
where not missing(depression);
<other analysis code>
run;
In modeling procedures like regression missing values of the model variables by default will be ignored for the model, nothing extra needed unless you want to use "missing" as a valid level for variables which is often an option.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Early bird rate extended! Save $200 when you sign up by March 31.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.