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!
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.