I have a SAS code that, from crosstab tables, generates mini datasets that are then run through Proc Report to generate individual report tables to show prevalence estimates & 95% CLs from survey items across 5 years.
There are about 55 individual variables, all with 2+ response categories.
Is it possible to get these all into one single table, so that each variable is still its own group, separated by a bold horizontal line?
** List of ~55 variables code iterates through;
%let crossnames= bpinsur dpinsur ppinsur . . . . . ;
ODS HTML;
%macro dothisb;
TITLE;
%do i=1 %to %sysfunc(countw(&crossnames));
%let thisname=%scan(&crossnames,&i,%str( ));
** Create Simplified crosstab datasets;
Data year3_&thisname;
Set year2_&thisname;
length newvar $20;
length CLS $12;
newvar=cat(put(Row_Percent, 4.1),' [',put(Lower_CL, 4.1),' ',put(Upper_CL, 4.1),']');
CLS=cat(' [',put(Lower_CL, 4.1),'-',put(Upper_CL, 4.1),']');
DROP RowPercent RowLowerCL RowUpperCL ;
Label newvar="%[95%CL]";
Label CLS="[95%CL]";
Run;
** PROC REPORT;
Proc report data=year3_&thisname out=report_&thisname
nowd CENTER WRAP
;
Column &thisname YY4_DOB,(Row_Percent CLS) dummyvar;
Define &thisname / order=internal group flow;
Define yy4_DOB / "Year" across;
Define Row_Percent / "%" display;
Define CLS / display ;
Define dummyvar / computed noprint ;
compute dummyvar;
dummyvar = 1;
endcomp;
Run;
%end;
ODS rtf CLOSE;
%mend;
%dothisb
Year | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
2016 | 2017 | 2018 | 2019 | 2020 | ||||||
Reported Insurance During | % | [95%CL] | % | [95%CL] | % | [95%CL] | % | [95%CL] | % | [95%CL] |
None | 3.2 | [1.2 - 4.2] | ||||||||
Private | ||||||||||
Medicaid |
Year | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
2016 | 2017 | 2018 | 2019 | 2020 | ||||||
Reported Insurance After | % | [95%CL] | % | [95%CL] | % | [95%CL] | % | [95%CL] | % | [95%CL] |
None | ||||||||||
Private | ||||||||||
Medicaid |
It is a good idea when requesting a custom appearing table to provide example data to test suggested code with.
Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the </> icon or attached as text to show exactly what you have and that we can test code against.
With what you show I suspect it is possible but would involve reshaping your data set so that you have the row variable as a single variable.
If you did not build character values to show the confidence limits you could build something that looks like that with Proc tabulate and some not too obnoxious style overrides and formats to make the intervals look like that but use the numeric values.
You can convert your 55 variables to a single variable that has the variable names, and a second that has the values within each variable name:
data have;
input a $ b $ var;
row = _N_;
datalines;
x x 1
x y 2
y x 3
;
proc transpose
data=have
out=long (rename=(_name_=group col1=level))
;
by row;
var a b;
run;
data long2;
merge
long
have (drop=a b)
;
by row;
run;
proc sort data=long2;
by group level;
run;
I use just two of your 55 variables, and a single variable that stands for all the values you want to report about.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.