BookmarkSubscribeRSS Feed
rsva
Fluorite | Level 6
I have a SAS dataset created from Proc Freq procedure and transposed. Below is the layout

E.g. Proc Freq;
Tables Sex*year;
Where year ge 2005 and year le 2007;
Run;

Present Output after transposing by sex
Sex Cnt2005 Cnt2006 Cnt2007 Pct2005 Pct2006 Pct2007
Male
Female

Problem: I need to repeat the analysis for other set of years as needed. E.g. instead of 2005-2007 I may need to use 2000 to 2005 in where statement. How do I modify VAR statement in Proc Print

In other words how do I modify the below statement without literally changing them in several proc print statement

VAR sex cnt2005 pct2005 cnt2006 pct2006 cnt2007 pct2007;

Thanks.
4 REPLIES 4
Patrick
Opal | Level 21
Hi

May be below example is a way to go?

data TransposeOutput;
sex=1;
pct2005=25;
cnt2006=50;
pct2007=10;
output;
run;

proc sql;
select name into :varlist separated by ' '
from dictionary.columns
where libname='WORK' and memname=%upcase('TransposeOutput')
;
quit;

proc print data=TransposeOutput;
var &varlist;
run;

HTH
Patrick
Peter_C
Rhodochrosite | Level 12
use a var statement like[pre] var sex cnt&from - cnt&to pct&from - pct&to ;[/pre]where &from and &to are the year range parameters of your macro

luck
peterC
Patrick
Opal | Level 21
Following Peter's approach you could also use a wildcard as below:

proc print data=TransposeOutput;
var sex pct: cnt:;
run;

This works under the assumption that you always want to print all year-variables in the transposed data set.
rsva
Fluorite | Level 6
Thanks to all who replied to my post. It worked.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1283 views
  • 0 likes
  • 3 in conversation