Libname Review'/folders/myfolders/Review' ; Libname Learn'/folders/myfolders/Learn' ; Libname myformat'/folders/myfolders/sasuser.v94' ; Options fmtsearch=(myformat) ; Data review.vitals ; input ID : $3. Age : 2. Pulse : 3. SBP : 3. DBP : 3. ; label SBP = "Systolic Blood Pressure" ; DBP = "Diastolic Blood Pressure" ; Datalines ; 001 23 68 120 80 002 55 72 188 96 003 78 82 200 100 004 18 58 110 70 005 43 52 120 82 005 43 52 120 82 006 37 74 150 98 007 . 82 140 100 ; proc print data=review.vitals noobs ; run ;
I can't figure out why not. Any suggestions? The output has missing data for all DBP values. All the other variable data points display correctly.
Assign length as opposed to format to override the execution pattern of taking the length of Low rather than a higher length
Data new_vitals ;
set vitals ;
length SBPGroup PulseGroup $8;/*correction*/
If Not Missing(Age) And Age lt 50 then do ;
If Pulse lt 70 then PulseGroup = 'Low' ;
else PulseGroup = 'High' ;
If SBP lt 130 then SBPGroup = 'Low' ;
else SBPgroup = 'High' ;
End ;
If Not Missing(Age) And Age ge 50 then do ;
If Pulse lt 74 then PulseGroup = 'Low' ;
else PulseGroup = 'High' ;
If SBP lt 140 then SBPGroup = 'Low' ;
else SBPgroup = 'High' ;
End ;
/* format PulseGroup $8. SBPGroup $8. ;*/
run ;
a small correction in your label statement
Data vitals ;
input ID : $3.
Age : 2.
Pulse : 3.
SBP : 3.
DBP : 3. ;
label SBP = "Systolic Blood Pressure"
DBP = "Diastolic Blood Pressure" ;
Datalines ;
001 23 68 120 80
002 55 72 188 96
003 78 82 200 100
004 18 58 110 70
005 43 52 120 82
005 43 52 120 82
006 37 74 150 98
007 . 82 140 100
;
Or if you want you can kick it to another statement entirely just for fun.
Data vitals ;
input ID $3. Age Pulse SBP DBP;
Datalines ;
001 23 68 120 80
002 55 72 188 96
003 78 82 200 100
004 18 58 110 70
005 43 52 120 82
005 43 52 120 82
006 37 74 150 98
007 . 82 140 100
;
data vitals;
set vitals;
label SBP = "Systolic Blood Pressure" ;
label DBP = "Diastolic Blood Pressure" ;
run;
Great. I didn't see that I had put a semicolon after SBP.
There is one other thing that is still bothering me... even when making the format for SBP group $8., 'high' is getting cut off to 'hig'. Why is that? Thanks. And, then I will certainly accept as solution.
Libname Review'/folders/myfolders/Review' ;
Libname Learn'/folders/myfolders/Learn' ;
Libname myformat'/folders/myfolders/sasuser.v94' ;
Options fmtsearch=(myformat) ;
Data review.vitals ;
input ID : $3.
Age : 2.
Pulse : 3.
SBP : 3.
DBP : 3. ;
label SBP = "Systolic Blood Pressure"
DBP = "Diastolic Blood Pressure" ;
Datalines ;
001 23 68 120 80
002 55 72 188 96
003 78 82 200 100
004 18 58 110 70
005 43 52 120 82
005 43 52 120 82
006 37 74 150 98
007 . 82 140 100
;
Data review.new_vitals ;
set review.vitals ;
If Not Missing(Age) And Age lt 50 then do ;
If Pulse lt 70 then PulseGroup = 'Low' ;
else PulseGroup = 'High' ;
If SBP lt 130 then SBPGroup = 'Low' ;
else SBPgroup = 'High' ;
End ;
If Not Missing(Age) And Age ge 50 then do ;
If Pulse lt 74 then PulseGroup = 'Low' ;
else PulseGroup = 'High' ;
If SBP lt 140 then SBPGroup = 'Low' ;
else SBPgroup = 'High' ;
End ;
format PulseGroup $8. SBPGroup $8. ;
run ;
proc print data=review.new_vitals noobs ;
run ;
Assign length as opposed to format to override the execution pattern of taking the length of Low rather than a higher length
Data new_vitals ;
set vitals ;
length SBPGroup PulseGroup $8;/*correction*/
If Not Missing(Age) And Age lt 50 then do ;
If Pulse lt 70 then PulseGroup = 'Low' ;
else PulseGroup = 'High' ;
If SBP lt 130 then SBPGroup = 'Low' ;
else SBPgroup = 'High' ;
End ;
If Not Missing(Age) And Age ge 50 then do ;
If Pulse lt 74 then PulseGroup = 'Low' ;
else PulseGroup = 'High' ;
If SBP lt 140 then SBPGroup = 'Low' ;
else SBPgroup = 'High' ;
End ;
/* format PulseGroup $8. SBPGroup $8. ;*/
run ;
Thanks!
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 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.