DATA Step, Macro, Functions and more

Proc report with DO and Conditional

Reply
Frequent Contributor
Posts: 130

Proc report with DO and Conditional

Hi.

 

I am trying to display the computed variable Hypertensive such that it is shown as "Hypertensive?" and is computed as 'Yes' or 'No' depending on conditional factors.

 

First of all, I am getting no display for yes or no if I leave the variable name as Hypertensive, as opposed to displaying Hyertensive?

Second, I have no idea how to convert the variable hypertensive to display hypertensive? in proc report.

 

 

Any help would be much appreciated. Thanks!

 

-----------------------------------

Libname Learn '/folders/myfolders/Learn' ;

Title "Hypertensive Patients" ;
proc report data=learn.BloodPressure nowd headline ls=80 ;
    columns Gender SBP DBP Hypertensive ;
    define SBP            / display "SBP" ;
    define DBP            / display "DBP" ;
    compute Hypertensive  / character length=8 ;
    define Hypertensive   / display "Hypertensive?" ;
        If Gender=F then do ;
            If (SBP gt 138 or DBP gt 88) then Hypertensive='Yes';
            else Hypertensive='No' ;
        end ;
        If Gender=M then do ;
            If (SBP gt 140 or DBP gt 90) then Hypertensive='Yes';
            else Hypertensive='No' ;
        end ;
    endcomp ;
run ;

Super User
Posts: 2,518

Re: Proc report with DO and Conditional

Posted in reply to ManitobaMoose

Like this?

 


proc report data=SASHELP.CLASS(obs=10);
    columns NAME SEX WEIGHT HYPERTENSIVE;
    compute HYPERTENSIVE  / character length=8 ;
        if SEX='F' then do ;
            if (WEIGHT.sum gt 100 ) then HYPERTENSIVE='Yes';
            else HYPERTENSIVE='No' ;
        end ;
        if SEX='M' then do ;
            if (WEIGHT.sum gt 110 ) then HYPERTENSIVE='Yes';
            else HYPERTENSIVE='No' ;
        end ;
    endcomp ;
run ;

 


Name Sex Weight HYPERTENSIVE
Alfred M 112.5 Yes
Alice F 84 No
Barbara F 98 No
Carol F 102.5 Yes
Henry M 102.5 No
James M 83 No
Jane F 84.5 No
Janet F 112.5 Yes
Jeffrey M 84 No
John M 99.5 No

 

 

Frequent Contributor
Posts: 130

Re: Proc report with DO and Conditional

Thanks.

 

As for getting the hypertensive to display 'true' or 'false', it was simple:

I did not put the gender ='f' and gender='m' in apostrophes, as I should have for a character variable. When I corrected this, after reading your post, it worked.

 

As for converting the variable hypertensive to hypertensive? for displaying on the proc report, I am not sure how to do this. However, I did get most of it. If anyone else has suggestions on this that would be great. If not, that is ok.

Frequent Contributor
Posts: 130

Re: Proc report with DO and Conditional

Posted in reply to ManitobaMoose

Libname Learn '/folders/myfolders/Learn' ;

Title "Hypertensive Patients" ;
proc report data=learn.BloodPressure nowd headline ls=80 ;
    columns Gender SBP DBP Hypertensive ;
    define SBP            / display "SBP" ;
    define DBP            / display "DBP" ;
    compute Hypertensive  / character length=8 ;
        If Gender='F' then do ;
            If (SBP gt 138 or DBP gt 88) then Hypertensive='Yes';
            else Hypertensive='No' ;
        end ;
        If Gender='M' then do ;
            If (SBP gt 140 or DBP gt 90) then Hypertensive='Yes';
            else Hypertensive='No' ;
        end ;
    endcomp ;
    hypertensive(rename=hypertensive?) ;
run ;

Valued Guide
Posts: 631

Re: Proc report with DO and Conditional

[ Edited ]
Posted in reply to ManitobaMoose

The question-mark  is not a valid char in a name. But you can assign a label to Hypertensive to be displayed as "Hypertensive?"

 

proc report data=SASHELP.CLASS(obs=10);
    columns NAME SEX WEIGHT HYPERTENSIVE;

    define HYPERTENSIVE / computed "Hypertensive?";

    compute HYPERTENSIVE  / character length=8 ;
        if SEX='F' then do ;
            if (WEIGHT.sum gt 100 ) then HYPERTENSIVE='Yes';
            else HYPERTENSIVE='No' ;
        end ;
        if SEX='M' then do ;
            if (WEIGHT.sum gt 110 ) then HYPERTENSIVE='Yes';
            else HYPERTENSIVE='No' ;
        end ;
    endcomp ;
run ;

 

Ask a Question
Discussion stats
  • 4 replies
  • 108 views
  • 0 likes
  • 3 in conversation