BookmarkSubscribeRSS Feed
ganeshsas764
Obsidian | Level 7

hi friends ,

any body clearify my doute ,

data set " A" have 100 observations(inputdataset), "B" output dataset,

 

in dataset " A" ,every 5th observation should come to data set "B" ,

 

let me clearify me?

5 REPLIES 5
Davanden
Obsidian | Level 7
One way to do this would be:

DATA B (DROP=count);
SET A;
RETAIN count 1;
IF count = 5 THEN DO;
OUTPUT;
count = 1;
END;
ELSE
count =count + 1;
RUN;
mbuchecker
Quartz | Level 8

or more simply:

data b;

   set a;

   if mod(_n_,5) = 0 then output;

run;

Michelle
PeterHobart
SAS Employee

The previous examples read every row then output every 5th.

Fine for a one-off run or a small sample.

This is more efficient technique which only reads every 5th row but it's slightly more code.

 

data b;

  do i = 1 to rows by 5;

  set a point=i nobs=rows;

  output;

  end;

stop;

run;

PeterHobart
SAS Employee

One more option, if you have SAS/Stat.

this will generate a randon 20% sample

 

proc surveyselect data=a out=b
rate=0.2;
run;
quit;

FreelanceReinh
Jade | Level 19

And if you have SAS/STAT 13.1 or higher, you can use PROC SURVEYSELECT also to literally select every 5th observation (without any random component):

proc surveyselect data=a out=b
method=sys(start=5) rate=0.2;
run;

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
  • 5 replies
  • 1013 views
  • 0 likes
  • 5 in conversation