BookmarkSubscribeRSS Feed
SASPhile
Quartz | Level 8

There are 13 mil records in a dataset. and there is column country_cd. I need to pull 20 records for each country_cd i.e

country_cd list that i'm interested is 001, 840, 124, 875.For each of this country code I need get 20 records.

Any help is appreciated.

2 REPLIES 2
Haikuo
Onyx | Level 15

Hi,

If I understand you correctly, the following code may get you to start:

data _w1/view=_w1;

  set have (where=(country_cd in ('001','840','124','875')));

run;

proc sort data=_w1;

by country_cd;

run;

data want;

  do _n_=1 by 1 until (last.country_cd);

  set _w1;

   by country_cd;

if _n_<=20 then output;

  end;

run;

Haikuo

SASPhile
Quartz | Level 8

I used somethng like this:

    proc sql;

        create table outdata.cntry_20 as

         select * from outdata._master_v1(obs=20) where ADR_CTRY_CD='000'

         union all

         select * from outdata._master_v1(obs=20) where ADR_CTRY_CD='840'      

         union all

         select * from outdata._master_v1(obs=20) where ADR_CTRY_CD='344'

         union all

         select * from outdata._master_v1(obs=20) where ADR_CTRY_CD='392'

         union all

         select * from outdata._master_v1(obs=20) where ADR_CTRY_CD='076';

      quit;

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
  • 782 views
  • 0 likes
  • 2 in conversation