- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I am trying to create a new variable to be merged back into the old data set from a frequency count. Below is a snap-shot of the output. The new variable I want to create is a frequency count of DUPERSID.
DUPERSID | Frequency | Percent | Cumulative Frequency | Cumulative Percent |
20002014 | 2 | 0 | 2 | 0 |
20002068 | 2 | 0 | 4 | 0 |
20003019 | 2 | 0 | 6 | 0.01 |
20003026 | 2 | 0 | 8 | 0.01 |
20003030 | 2 | 0 | 10 | 0.01 |
20004018 | 2 | 0 | 12 | 0.01 |
20007016 | 2 | 0 | 14 | 0.02 |
20007023 | 2 | 0 | 16 | 0.02 |
20007030 | 2 | 0 | 18 | 0.02 |
20012018 | 1 | 0 | 19 | 0.02 |
20012025 | 1 | 0 | 20 | 0.02 |
20013017 | 1 | 0 | 21 | 0.02 |
20014017 | 2 | 0 | 23 | 0.03 |
20014024 | 2 | 0 | 25 | 0.03 |
20015019 | 2 | 0 | 27 | 0.03 |
The code I used was as follows:
PROC FREQ DATA = TEST NOPRINT;
TABLES DUPERSID/
OUT=COUNTS (KEEP=DUPERSID COUNT RENAME=COUNT(DUPERSID_COUNTS));
RUN;
I did not receive an error code in log, however, when I run a proc freq:
PROC FREQ DATA = TEST;
TABLES DUPERSID_COUNTS;
RUN;
It says "variable not found." Any suggestions?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Your second PROC FREQ is still pointed at the TEST data set, but you called it COUNTS.
PROC FREQ DATA = TEST NOPRINT;
TABLES DUPERSID/
OUT=COUNTS (KEEP=DUPERSID COUNT RENAME=COUNT(DUPERSID_COUNTS));
RUN;
PROC FREQ DATA = TEST;
TABLES DUPERSID_COUNTS;
RUN;
An easier way to do this is to either merge it in or to use SQL.
proc sql;
create table want as
select *, count( dupersid) as count_dupersid
from have
group by dupersid;
quit;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Many thanks, got that to work out now. Did not know about PROC SQL, will try that as well.