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?
@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;
A COMPUTED variable which is always assigned 1?
Yes, is this possible to do? I'm quite unfamiliar with proc report.
@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;
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 |
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;
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;
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;
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
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.