DATA Step, Macro, Functions and more

reading file random without point

Accepted Solution Solved
Reply
Contributor
Posts: 44
Accepted Solution

reading file random without point

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


Accepted Solutions
Solution
‎08-28-2014 07:43 AM
Respected Advisor
Posts: 3,799

Re: reading file random without point

set have have have;

View solution in original post


All Replies
Solution
‎08-28-2014 07:43 AM
Respected Advisor
Posts: 3,799

Re: reading file random without point

set have have have;

Super User
Posts: 10,035

Re: reading file random without point

And check some functions about it like   fetchobs( )  .

Super User
Super User
Posts: 7,970

Re: reading file random without point

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.

Contributor
Posts: 44

Re: reading file random without point

sorry.

could u pls provide me the logic

Trusted Advisor
Posts: 1,228

Re: reading file random without point

One more way

proc sql;

select * from have

union all

select * from have

union all

select * from have;

quit;

Respected Advisor
Posts: 4,926

Re: reading file random without point

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

data want / view=want;

set have have have;

run;

PG

PG
Super User
Posts: 5,512

Re: reading file random without point

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

Super User
Super User
Posts: 7,970

Re: reading file random without point

Posted in reply to Astounding

First rule of obfuscation club is...

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 319 views
  • 6 likes
  • 7 in conversation