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 already have a file in which each variable has noduplicate value.

I want to create a summary file that show the number of value for each variable in a different format as below

data have;
input a b c;
cards;
1 1 2
-2 2 .
5 3 .
6 . .
run;

 

data want has 2 column: variable_name and number

a 4  meaning there are 4 values with variable a

b 3

c 1

 

Since there are hundreds of variables, I dont know how to make it work efficiently.

 

Any help is very much appreciated.

 

HHC

 

****************************************************


proc summary data=have noprint;
var _numeric_;
output out = a n=; run;

 

proc transpose data=a out=a1;
var _numeric_;
run;



Proc means data=have stackods N NMISS;
var _numeric_;
ods output summary=want;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Since there are no duplicate values, this is really just a count of how many non-missing values exist.  This will get it horizontally:

 

proc summary data=have;

var _numeric_;

output out=stats (drop=_type_ _freq_) n=;

run;

 

At this point you could either use the data set STATS, or you could transpose it to get what you described as the WANT data set:

 

proc transpose data=stats out=want (rename=(col1=number));

var _numeric_;

run;

View solution in original post

2 REPLIES 2
Astounding
PROC Star

Since there are no duplicate values, this is really just a count of how many non-missing values exist.  This will get it horizontally:

 

proc summary data=have;

var _numeric_;

output out=stats (drop=_type_ _freq_) n=;

run;

 

At this point you could either use the data set STATS, or you could transpose it to get what you described as the WANT data set:

 

proc transpose data=stats out=want (rename=(col1=number));

var _numeric_;

run;

Reeza
Super User

Proc means with N statistic should calculate this. 

 

Ods select none;

Proc means data=SASHELP.class stackods N NMISS;

var _numeric_;

ods output summary=want;

run;

ods select all;

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
  • 2 replies
  • 720 views
  • 1 like
  • 3 in conversation