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

Hi Everyone,

I want to run proc freq to create a table with each column reporting frequency of each variable in the original dataset.


My original data variables only take value 1, 2 ,3. So it will be quite convenient to get that summary table since it only have 3 row (1,2,3)

I guess there should be a way to do it rather than getting table one by one and combine them with proc sql.

The output should be in the format:

value       var1    var2    var3

1

2

3

Thank you for your help.

HHC

data have;

input var1 var2 var3

datalines;

1 1 1

2 1 2

3 1 2

1 2 3

;run;

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

It might take a little reshaping of your data, but it's not lengthy.

data reshape;

   set have;

   array vars {5} var1-var5;

   do _i_=1 to 5;

      varname = vname(vars{_i_});

      value = vars{_i_};

      output;

   end;

   keep varname value;

run;

proc tabulate data=reshape;

   class varname value;

   tables value, varname * N=' ' * f=12.;

run;

Personally, I might prefer one variable per row instead of one per column, such as (all else remaining the same):

   tables varname, N * value=' ' * f=12.   PCTN <value> * value=' ' ;

Good luck.

View solution in original post

3 REPLIES 3
Reeza
Super User

proc tabulate will do that to that to a destination, but not sure what the output tables look like.

ballardw
Super User

What do you want the output to look like? summary for values Var1,2,3 stacked vertically? horizontally? row headings of 1,2,3 with a column count for each of your variables?

Lots of ways to combine frequency counts but what you want for a final product will affect the approach.

Astounding
PROC Star

It might take a little reshaping of your data, but it's not lengthy.

data reshape;

   set have;

   array vars {5} var1-var5;

   do _i_=1 to 5;

      varname = vname(vars{_i_});

      value = vars{_i_};

      output;

   end;

   keep varname value;

run;

proc tabulate data=reshape;

   class varname value;

   tables value, varname * N=' ' * f=12.;

run;

Personally, I might prefer one variable per row instead of one per column, such as (all else remaining the same):

   tables varname, N * value=' ' * f=12.   PCTN <value> * value=' ' ;

Good luck.

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