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

how to read observations from a dataset 3 times,how many ways(without point)

have dataset:

ranks

1

2

want dataset:

ranks

1

2

1

2

1

2

1 ACCEPTED SOLUTION

Accepted Solutions
8 REPLIES 8
data_null__
Jade | Level 19

set have have have;

Ksharp
Super User

And check some functions about it like   fetchobs( )  .

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Can I check why?  It seems in your example you want a dataset with a 1, 2 combination 3 times.  There are better ways than creating one dataset and then appending that three times, do loops for instance, retain statement setting the value != previous etc.

rajeshm
Quartz | Level 8

sorry.

could u pls provide me the logic

stat_sas
Ammonite | Level 13

One more way

proc sql;

select * from have

union all

select * from have

union all

select * from have;

quit;

PGStats
Opal | Level 21

If you don't want to waste space, create a view:

data want / view=want;

set have have have;

run;

PG

PG
Astounding
PROC Star

How silly are we allowed to get?  Why write something simple when you can confuse everybody with a macro?

%macro silly;

%local N i j;

data _null_;

   set have nobs=_total_obs_;

   call symputx ('N', _total_obs_);

run;
data want;

   %do i=1 %to 3;

      %do j=1 %to &N;

         set have (firstobs=&j obs=&j);

         output;

      %end;

   %end;

run;

%mend silly;

%silly

RW9
Diamond | Level 26 RW9
Diamond | Level 26

First rule of obfuscation club is...

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
  • 1033 views
  • 6 likes
  • 7 in conversation