BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
vicky07
Quartz | Level 8

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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;


View solution in original post

8 REPLIES 8
Haikuo
Onyx | Level 15

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

PGStats
Opal | Level 21

Hi Haikuo, I think OP wants a cross tabulation, not individual frequency tables for each variable.

PG

PG
Haikuo
Onyx | Level 15

Ah, miss that part. Consider it excusable for being Sunday afternoon where people feel worse than Monday morning Smiley Happy.

PGStats
Opal | Level 21

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

PG
vicky07
Quartz | Level 8

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?)

data_null__
Jade | Level 19

Just change MEANS to SUMMRY and omit the VAR statement.  _FREQ_ will be a variable in the output data that represents the counts.

Tom
Super User Tom
Super User

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;


vicky07
Quartz | Level 8

Thanks Tom,Data _null_ , Hai.Kuo and PGStats.

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!

What is Bayesian Analysis?

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.

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
  • 8 replies
  • 925 views
  • 3 likes
  • 5 in conversation