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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 4 replies
  • 1022 views
  • 0 likes
  • 3 in conversation