BookmarkSubscribeRSS Feed
viancapole
Calcite | Level 5

 

When I run the code for the table the variables:  w1evsmk     w1evdrk     w1_hgt_in  w1cursmk don't show the data and instead, it just shows points (.). What I am doing wrong?

 

DATA work.lab1;
SET saslab.da21600p1;

 

If H1TO1 = 1 and H1TO2 ^= 0 then w1evsmk=1;
else if H1TO1 = 0 or H1TO2 = 0 then w1evsmk=0;
label w1evsmk = Wave 1 - ever smoked a whole cigarette;


if H1TO3 = 1 then dailysmkev=1;
else if H1TO3=0 or ne 6 then dailysmkev=0;
label dailysmkev = ever smoked daily for at least 30 days;

if w1evsmk=1 then do;
if H1TO5 ge 1 and H1TO5 lt 32 then days_smk=h1TO5;

label days_smk = number of days smoked in past month among ever smokers;

if H1TO7 lt 90 then num_cigs = H1TO7;
label num_cigs = number cigarettes per day in past 30 days;


if w1evsmk = 1 and days_smk gt 0 then w1cursmk=2;
else if w1evsmk = 1 then w1cursmk=1;
else if w1evsmk = 0 then w1cursmk=0;
label w1cursmk = current, former, or never smoker;

 

if h1to12 =1 then w1evdrk=1;
else if h1to12=0 then w1evdrk=0;
label w1evdrk = Wave 1 - ever had more than 2-3 drinks;

if h1to30 in (0) then w1evmj=0;
else if h1to30 not in (96, 99) then w1evmj=1;
label w1evmj = Wave 1 - ever tried marijuana;

 

if h1to34 = 0 then w1evcocaine=0;
else if h1to34 not in (96, 99) then w1evcocaine = 1;
label w1evcocaine = Wave 1 - ever tried cocaine;

 

if pa56 = 1 then poverty=0;
else if pa56=0 then poverty=1;
label poverty = parent reported not enough money to pay bills;

 

if w1_hgt_in=(H1GH59A*12) + H1GH59B;
LABEL w1_hgt_in = total height in inches at Wave 1;

if H1GH60 le 360 then w1_wgt = H1GH60;
LABEL w1_wgt = Self-reported weight in lbs at Wave 1;

 

keep AID w1evsmk w1evdrk w1evmj w1_hgt_in w1_wgt w1cursmk ethrace male;
END;
RUN;


PROC FREQ DATA=work.lab1;
Tables w1evsmk w1evdrk w1_hgt_in ethrace w1cursmk / list missprint;
FORMAT ethrace;
RUN;

 

 

2 REPLIES 2
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

should labels have quotes?

do you need to declare the variables w1evsmk w1evdrk and such.

If you post data in the form of a data step so that the variables formats are known it would be a lot easier to assist you.

 

Astounding
PROC Star

Of course, we are only guessing.  But here are a few reasonable guesses.

 

First, did you actually read the log to see whether there were any important messages?  At a minimum, the issue that @VDD mentioned about labels being in quotes comes to mind.

 

Secondly, the logic is probably off.  It looks like you got a message about needing a matching END statement, and just stuck one in at the end of the program to remove the error.  But that doesn't make the logic correct.  More likely, it should be placed much closer to the DO statement.  As it stands now, most of your DATA step executes only when w1evsmk=1 ... since that never happens, it is no surprise that your other new variables are always missing.

 

Finally, there's no evidence that you actually examined the data to see whether the results are correct.  You run a PROC FREQ at the end.  How about adding:

 

tables H1TO1 * H1TO2;

 

Then you would have some basis to see whether results for W1EVSMK are correct or not.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 758 views
  • 1 like
  • 3 in conversation