turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- Summary file for discrete value

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

01-19-2017 10:25 PM - edited 01-20-2017 10:09 AM

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;

Accepted Solutions

Solution

01-20-2017
10:08 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to hhchenfx

01-19-2017 10:57 PM

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;

All Replies

Solution

01-20-2017
10:08 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to hhchenfx

01-19-2017 10:57 PM

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;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to hhchenfx

01-19-2017 11:00 PM

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;