Hello,
I'm wondering if there is a way to use to '-' or ':' to assign range of variable list in table statement in cross frequency?
I have range of variables list from Flag1-Flag6 and I want to use proc freq as below.
Proc Freq data = abc123;
tables statecd*age*Flag1*Flag2*Flag3*Flag4*Flag5*Flag6/list missing;
Run;
Is there a easy way to write the list of Flag variable in table statement and avoid typing individually?
Thanks!
If you do not want to cross the flags with each other then the you can use:
tables statecd*age*(Flag1-Flag6)
As short cut for statecd*age*flag1 statecd*age*flag2 ....
If you do want to cross all of them and do not need the percents then use proc means with NWAY option, CLASS statement and no VAR statement.
proc means nway ;
class statecd age flag1-flag6 / missing;
run;
Since you mentioned using '-' to refer variable list, I bet you haven't tried it, as if you did, you would have found that it worked the way you guessed:
Proc Freq data = abc123;
tables statecd age Flag1-Flag6/list missing;
Run;
It gets better if all of these variables are adjacent to each other:
Proc Freq data = abc123;
tables statecd --Flag6/list missing;
Run;
Haikuo
Hi Haikuo, I think OP wants a cross tabulation, not individual frequency tables for each variable.
PG
Ah, miss that part. Consider it excusable for being Sunday afternoon where people feel worse than Monday morning .
You can use variable lists with proc means:
proc means data = abc123 nway noprint;
class statecd--flag6 / missing;
var statecd;
output out=want(keep=statecd--flag6 n) n(statecd)=n;
run;
PG
PGStats - Thanks for your reply. I tried running your code but getting the following error "Variable Statecd in list does not match type prescribed for this list". It is printing right below the var statement. Statcd is character variable. Also I want cross tabulation of Statecd , AGE and Flag variables( i don't see mention of AGE in your code, not sure if statecd--flag6 include AGE variable as well?)
Just change MEANS to SUMMRY and omit the VAR statement. _FREQ_ will be a variable in the output data that represents the counts.
If you do not want to cross the flags with each other then the you can use:
tables statecd*age*(Flag1-Flag6)
As short cut for statecd*age*flag1 statecd*age*flag2 ....
If you do want to cross all of them and do not need the percents then use proc means with NWAY option, CLASS statement and no VAR statement.
proc means nway ;
class statecd age flag1-flag6 / missing;
run;
Thanks Tom,Data _null_ , Hai.Kuo and PGStats.
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.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.