BookmarkSubscribeRSS Feed
dishant
Calcite | Level 5

Hi all,

My data set is Like This,

data chk;

  input x;

  datalines;

12

23

34

11

45

;

Run;

And My desired Output Look Like,

12

12

23

12

23

34

12

23

34

11

12

23

34

11

45

So Pls Guys Help Me out in this problem. Your Valuable Suggestion appreciate.

Thanks In Advance.

Regards,

Dishant Parikh

8 REPLIES 8
Peter_C
Rhodochrosite | Level 12

dishant

please

before I offer a solution

why!

is it really just a repeat of the first N obs where N goes from 1 to 5?

Message was edited by: Peter Crawford

dishant
Calcite | Level 5

Hi peter,

Actually I am Creating one Macro This Solution Will Helpful me a lot.

can you help me to reach the required output ,it would be grateful.

Peter_C
Rhodochrosite | Level 12

data fun;

do y= 1 to _n_ ;

  set chk point= y ;

  output ;

end ;

if _n_ >= 5 then stop ;

run ;

dishant
Calcite | Level 5

Hi Peter,


Thanks A lot For giving the answer and your valuable time.This Solution Will Helpful me a lot.


One More Question we can do with the any other logic or procedure?


Peter_C
Rhodochrosite | Level 12

Why is that not an adequate anserr?

did your One Macro need something else?

Message was edited by: Peter Crawford

dishant
Calcite | Level 5

Hi Peter,

yeah obviously its adequate answer and it takes me new level of thinking but as per your logic we need to pass total _n_  in if condition.

If suppose data get updated and few more observation added then again we need to change the if condition right?

So is their any logic in dynamic way.

Thanks In advance.

Peter_C
Rhodochrosite | Level 12

what error messages are you getting?

data_null__
Jade | Level 19

If you visit the online documentation regarding the SET statement you will find the NOBS option.  Which should suffice for what you call "total _N_".

data chk;
  input x;
  datalines;
12
23
34
11
45
;
Run;

data fun;
   group = _n_;
  
do y= 1 to _n_;
      set chk point=y nobs=nobs;
      output;
     
end;
  
if _n_ >= nobs then stop;
  
run;
proc print;
  
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
  • 8 replies
  • 941 views
  • 0 likes
  • 3 in conversation