BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
EC27556
Quartz | Level 8

Hi I have some code that looks like this:

proc report data=sashelp.heart split='~' nowd ;
	
	column status status2 sex sex2 bp_status bp_status2 MRW,Smoking_Status;
	
	define Smoking_Status / Across;
	define status / Group noprint;
	define sex / Group noprint;
	define bp_status / Group noprint;
	define MRW / sum '';

	define status2 / computed;
	define sex2 / computed;
	define bp_status2 / computed;

compute before bp_status;
_status=status;
_sex=sex;
_bp_status=bp_status;
endcomp;

compute status2/character length=40;
status2=_status;
endcomp;
compute sex2/character length=40;
sex2=_sex;
endcomp;
compute bp_status2/character length=40;
bp_status2=_bp_status;
endcomp;
run;

In the table, between the columns of bp_status2 and Heavy (16-25) I want a column titled "Outcomes" which just has the value of 1 for every row. This isnt a variable that exists currently on sashelp.heart but is this still possible to achieve? If so, does anyone know how?

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

@EC27556 wrote:

Yes, is this possible to do? I'm quite unfamiliar with proc report.


See this:

proc report data=sashelp.heart split='~' nowd ;
	
	column status status2 sex sex2 bp_status bp_status2 MRW,Smoking_Status;
	
	define Smoking_Status / Across;
	define status / Group noprint;
	define sex / Group noprint;
	define bp_status / Group noprint;
	define MRW / sum '';

	define status2 / computed;
	define sex2 / computed;
	define bp_status2 / computed;

compute before bp_status;
_status=status;
_sex=sex;
_bp_status=bp_status;
endcomp;

compute status2/character length=40;
status2=_status;
endcomp;
compute sex2/character length=40;
sex2=_sex;
endcomp;
compute bp_status2/character length=40;
bp_status2=_bp_status;
endcomp;
run;

View solution in original post

7 REPLIES 7
EC27556
Quartz | Level 8

Yes, is this possible to do? I'm quite unfamiliar with proc report.

Kurt_Bremser
Super User

@EC27556 wrote:

Yes, is this possible to do? I'm quite unfamiliar with proc report.


See this:

proc report data=sashelp.heart split='~' nowd ;
	
	column status status2 sex sex2 bp_status bp_status2 MRW,Smoking_Status;
	
	define Smoking_Status / Across;
	define status / Group noprint;
	define sex / Group noprint;
	define bp_status / Group noprint;
	define MRW / sum '';

	define status2 / computed;
	define sex2 / computed;
	define bp_status2 / computed;

compute before bp_status;
_status=status;
_sex=sex;
_bp_status=bp_status;
endcomp;

compute status2/character length=40;
status2=_status;
endcomp;
compute sex2/character length=40;
sex2=_sex;
endcomp;
compute bp_status2/character length=40;
bp_status2=_bp_status;
endcomp;
run;
Norman21
Lapis Lazuli | Level 10

But that doesn't answer the question!

 
  Smoking Status
status2 sex2 bp_status2 Heavy (16-25) Light (1-5) Moderate (6-15) Non-smoker Very Heavy (> 25)
Alive Female High 5927 10343 6070 56997 1105
Alive Female Normal 12955 17817 12365 59314 2040
Alive Female Optimal 6859 7945 7402 23389 1584
Alive Male High 14695 3485 4996 25251 8327
Alive Male Normal 21304 4603 6685 24049 11241
Alive Male Optimal 6489 1414 2826 6839 3159
Dead Female High 6954 7483 5694 50404 2200
Dead Female Normal 4144 4518 4438 16531 951
Dead Female Optimal 2021 1848 1629 3044 584
Dead Male High 20820 5698 6990 26980 15744
Dead Male Normal 14253 2775 5176 14331 7770
Dead Male Optimal 4242 451 940 2494 1337
Norman.
SAS 9.4 (TS1M6) X64_10PRO WIN 10.0.17763 Workstation

Kurt_Bremser
Super User

I still had your code in the clipboard, not my expanded code.

See now:

proc report data=sashelp.heart split='~' nowd ;
	
	column status status2 sex sex2 bp_status bp_status2 Outcomes MRW,Smoking_Status;
	
	define Smoking_Status / Across;
	define status / Group noprint;
	define sex / Group noprint;
	define Outcomes / computed;
	define bp_status / Group noprint;
	define MRW / sum '';

	define status2 / computed;
	define sex2 / computed;
	define bp_status2 / computed;

compute before bp_status;
_status=status;
_sex=sex;
_bp_status=bp_status;
endcomp;

compute Outcomes / character length=1;
  Outcomes = "1";
endcomp;

compute status2/character length=40;
status2=_status;
endcomp;
compute sex2/character length=40;
sex2=_sex;
endcomp;
compute bp_status2/character length=40;
bp_status2=_bp_status;
endcomp;
run;
Norman21
Lapis Lazuli | Level 10

It ain't pretty but is this what you mean?

 

proc report data=sashelp.heart split='~' nowd ;
	
	column status status2  sex sex2 bp_status bp_status2 outcomes MRW,Smoking_Status;
	
	define Smoking_Status / Across;
	define status / Group noprint;
	define sex / Group noprint;
	define bp_status / Group noprint;
	define MRW / sum '';

	define status2 / computed;
	define sex2 / computed;
	define bp_status2 / computed;
	define outcomes / computed;

compute before bp_status;
_status=status;
_sex=sex;
_bp_status=bp_status;
endcomp;

compute status2/character length=40;
status2=_status;
endcomp;
compute sex2/character length=40;
sex2=_sex;
endcomp;
compute bp_status2/character length=40;
bp_status2=_bp_status;
endcomp;

compute outcomes ;
outcomes = 1 ;
endcomp;

run;
Norman.
SAS 9.4 (TS1M6) X64_10PRO WIN 10.0.17763 Workstation

Ksharp
Super User
proc report data=sashelp.heart split='~' nowd ;
	
	column status status2 sex sex2 bp_status bp_status2  Outcomes    MRW,Smoking_Status;
	
	define Smoking_Status / Across;
	define status / Group noprint;
	define sex / Group noprint;
	define bp_status / Group noprint;
	define MRW / sum '';

	define status2 / computed;
	define sex2 / computed;
	define bp_status2 / computed;
	define Outcomes/ computed;

compute before bp_status;
_status=status;
_sex=sex;
_bp_status=bp_status;
endcomp;

compute status2/character length=40;
status2=_status;
endcomp;
compute sex2/character length=40;
sex2=_sex;
endcomp;
compute bp_status2/character length=40;
bp_status2=_bp_status;
endcomp;
compute Outcomes/character length=40;
Outcomes='1';
endcomp;


run;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 7 replies
  • 867 views
  • 2 likes
  • 4 in conversation