BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ManitobaMoose
Quartz | Level 8
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.

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

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 ;

View solution in original post

5 REPLIES 5
novinosrin
Tourmaline | Level 20

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
;
HB
Barite | Level 11 HB
Barite | Level 11

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;
ManitobaMoose
Quartz | Level 8

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 ;

novinosrin
Tourmaline | Level 20

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 ;

sas-innovate-2024.png

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.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1605 views
  • 0 likes
  • 3 in conversation