BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
xxformat_com
Barite | Level 11

Hi,

 

The table outputted by proc freq do not have the same structure i.e.

  • We have the variable NAME in the first table, SEX inthe second table, AGE in he third table...
  • We do not have two common variables in each table such as VARNAME and VARVALUE.

What would you suggest to have exactly the same variables in all the output datasets before appending them?

 

ods output OneWayFreqs(match_all)=demo;

proc freq data=sashelp.class nlevels;
    table _all_;
run;

data freq_all;
    set demo:;
run;

proc print data=freq_all;
run;

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Kathryn_SAS
SAS Employee

PROC FREQ does not require that you use MATCH_ALL any more. I would suggest the following SAS Sample which creates one output data set and then reshapes it into a more readable format.

https://support.sas.com/kb/37/780.html 

View solution in original post

3 REPLIES 3
FreelanceReinh
Jade | Level 19

Hi @xxformat_com,

 

A common variable VARVALUE containing NAME and AGE values must be a character variable. This is what PROC TRANSPOSE creates when transposing from wide to long. Then you can apply PROC FREQ to the "long" dataset.

 

Example:

data tmp / view=tmp;
seqno=_n_;
set sashelp.class;
run;

proc transpose data=tmp name=varname out=long(drop=seqno rename=(col1=varvalue));
by seqno;
var name--weight;
run;

proc sort data=long;
by varname;
run;

proc freq data=long noprint;
by varname;
tables varvalue / out=want;
run;
Kathryn_SAS
SAS Employee

PROC FREQ does not require that you use MATCH_ALL any more. I would suggest the following SAS Sample which creates one output data set and then reshapes it into a more readable format.

https://support.sas.com/kb/37/780.html 

FreelanceReinh
Jade | Level 19

One of the advantages of @Kathryn_SAS's solution is that (by virtue of the VVALUEX function) it would honor formats that are permanently associated with variables in the input dataset. My PROC TRANSPOSE approach would do so only for numeric variables (and it creates an additional dataset, albeit with optimized lengths of variables VARNAME and VARVALUE).

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 315 views
  • 4 likes
  • 3 in conversation