BookmarkSubscribeRSS Feed
buder
Fluorite | Level 6

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. 

 

DUPERSIDFrequencyPercentCumulative FrequencyCumulative Percent
200020142020
200020682040
200030192060.01
200030262080.01
2000303020100.01
2000401820120.01
2000701620140.02
2000702320160.02
2000703020180.02
2001201810190.02
2001202510200.02
2001301710210.02
2001401720230.03
2001402420250.03
2001501920270.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? 

 

 

 

 

2 REPLIES 2
Reeza
Super User

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;
buder
Fluorite | Level 6

Many thanks, got that to work out now. Did not know about PROC SQL, will try that as well.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 3453 views
  • 0 likes
  • 2 in conversation