DATA Step, Macro, Functions and more

Variable not showing up on dataset (in this case DBP)

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 119
Accepted Solution

Variable not showing up on dataset (in this case DBP)

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.


Accepted Solutions
Solution
‎04-18-2018 01:04 PM
PROC Star
Posts: 1,294

Re: Variable not showing up on dataset (in this case DBP)

[ Edited ]
Posted in reply to ManitobaMoose

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


All Replies
PROC Star
Posts: 1,294

Re: Variable not showing up on dataset (in this case DBP)

Posted in reply to ManitobaMoose

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
;
Super Contributor
Super Contributor
Posts: 260

Re: Variable not showing up on dataset (in this case DBP)

Posted in reply to novinosrin

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;
Frequent Contributor
Posts: 119

Re: Variable not showing up on dataset (in this case DBP)

Posted in reply to novinosrin

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 ;

Solution
‎04-18-2018 01:04 PM
PROC Star
Posts: 1,294

Re: Variable not showing up on dataset (in this case DBP)

[ Edited ]
Posted in reply to ManitobaMoose

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 ;
Frequent Contributor
Posts: 119

Re: Variable not showing up on dataset (in this case DBP)

Posted in reply to novinosrin

Thanks!

☑ This topic is solved.

Need further help from the community? Please ask a new question.

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