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

Hi, my data was simplified as following, and I wanna count the number of obsevations whose cusip is unique and yymm_a is unique. In this dataset, I wanna the result will be 4. How can I do this ?Thanks.

data WORK.TMP;
  infile datalines dsd truncover;
  input cusip:$8. yymm_a:YYMMN6.;
  format yymm_a YYMMN6.;
  label cusip="CUSIP/SEDOL";
datalines4;
00036020,199801
00036020,199801
00036020,199801
00036020,199801
00036020,199801
00036020,199801
00036020,199801
00036020,199801
00036020,199801
00036110,199705
00036110,199705
00036110,199705
00036110,199705
00036110,199705
00036110,199705
00036110,199705
00036110,199705
00036110,199705
00036110,199705
00036110,199810
00036110,199810
00036110,199810
00036110,199810
00036110,199810
00036110,199810
00036110,199810
00036110,199810
00036110,199810
00036110,199810
00036110,200009
;;;;
1 ACCEPTED SOLUTION

Accepted Solutions
collinelliot
Barite | Level 11

You could do this:

proc sql;
    SELECT count(DISTINCT cusip||put(yymm_a, date9.)) FROM your_data;
quit;

You could also do a frequency table of the two, output a dataset, and get the count of observations.

View solution in original post

5 REPLIES 5
collinelliot
Barite | Level 11

You could do this:

proc sql;
    SELECT count(DISTINCT cusip||put(yymm_a, date9.)) FROM your_data;
quit;

You could also do a frequency table of the two, output a dataset, and get the count of observations.

lixuan
Obsidian | Level 7

Hi, thanks a lot. I can't imagine || can be used like this .

andreas_lds
Jade | Level 19

Interesting idea, i would replace the counting data-step with proc means or with a query selecting nobs from sashelp.vtable. Would be interesting to see which soiution is more efficient when large datasets are involved.

ballardw
Super User

@dancy0824 Please post code as text, best is in a code box using the forum {i} menu icon or the SAS run icon.

Pictures that require others to retype the code discourage actually testing/using the code.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 2051 views
  • 4 likes
  • 5 in conversation