Dear Folks, plz help me with the following program:
data chk_10;
input sno name $ level;
if level = . then exp = 'unknown';
else if level = 1 then exp = 'low';
else if level = 2 or 3 then exp = 'medium';
else exp = 'high';
datalines;
1 Frank 1
2 John 2
3 sui 2
4 sose 1
5 burt 4
6 kelly .
7 juan 1
;
run;
proc print data = chk_10;
title 'chk1-0';
run;
I want in output that for the observation, which has level value as 4, i should get exp = 'high'--
but output is not showing that. in output - for level 4, exp is coming to be 'medium' --
but i am not able to se why is it so.
Appreciate your help-
The problem is 'if level = 2 or 3' The answer to this is always yes.
data chk_10;
input sno name $ level;
if level = . then exp = 'unknown';
else if level = 1 then exp = 'low';
else if level = 2 or level = 3 then exp = 'medium';
else exp = 'high';
datalines;
1 Frank 1
2 John 2
3 sui 2
4 sose 1
5 burt 4
6 kelly .
7 juan 1
;
run;
Another way would be to put if level > 3 then exp = 'high';
The problem is 'if level = 2 or 3' The answer to this is always yes.
data chk_10;
input sno name $ level;
if level = . then exp = 'unknown';
else if level = 1 then exp = 'low';
else if level = 2 or level = 3 then exp = 'medium';
else exp = 'high';
datalines;
1 Frank 1
2 John 2
3 sui 2
4 sose 1
5 burt 4
6 kelly .
7 juan 1
;
run;
Another way would be to put if level > 3 then exp = 'high';
The condition (LEVEL=2 or 3) is the same as ((LEVEL=2) or 3). Since 3 is always true this condition is always true.
Thanks, could you just help me with another one?
prog is:
data test_26;
infile Q26;
input empname $ 1-4;
if empname = 'Ruth' then input idnum 10-11;
else input age 7-8;
run;
proc print data = test_26;
title 'q26';
run;
input is :
Ruth 23 46
DP 45 19
Cali 34 23
Ruth 21 89
output is coming as:
empname idnum age
Ruth 19 .
Cali . 21
I understand that while reading first record, only empname is read and the pointer moves to the second row - but I am not able to understand rest of the output.
Please help.
Your first input statement
input empname $ 1-4;
tells SAS to load the contents of columns 1 to 4 into empname and step on to the next record. To keep hold of the same record in case you need to load more data from it later in the data step, you need to use the trailing @ notation:
input empname $ 1-4 @;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.