Help using Base SAS procedures

how to write var list in freq report?

Accepted Solution Solved
Reply
Contributor
Posts: 71
Accepted Solution

how to write var list in freq report?

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!


Accepted Solutions
Solution
‎06-09-2013 06:40 PM
Super User
Super User
Posts: 6,499

Re: how to write var list in freq report?

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


All Replies
Respected Advisor
Posts: 3,124

Re: how to write var list in freq report?

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

Respected Advisor
Posts: 4,644

Re: how to write var list in freq report?

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

PG

PG
Respected Advisor
Posts: 3,124

Re: how to write var list in freq report?

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

Respected Advisor
Posts: 4,644

Re: how to write var list in freq report?

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
Contributor
Posts: 71

Re: how to write var list in freq report?

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

Respected Advisor
Posts: 3,777

Re: how to write var list in freq report?

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

Solution
‎06-09-2013 06:40 PM
Super User
Super User
Posts: 6,499

Re: how to write var list in freq report?

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;


Contributor
Posts: 71

Re: how to write var list in freq report?

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

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 296 views
  • 3 likes
  • 5 in conversation