DATA Step, Macro, Functions and more

data manipulation

Accepted Solution Solved
Reply
Contributor
Posts: 62
Accepted Solution

data manipulation

Hi to all,

How to perfume that esealy without using iml ?

Regards

 

data have;

 

q        0.2

w       0.3

e        0.4

r        0.5

t        0.6

y       0.11

 

data want:

 

q        w        e        r        t         y

 

0.2     0.3     0.4     0.5     0.6     0.11

0.2     0.3     0.4     0.5     0.6     0.11

0.2     0.3     0.4     0.5     0.6     0.11

0.2     0.3     0.4     0.5     0.6     0.11

0.2     0.3     0.4     0.5     0.6     0.11

... n time the sames lines, n known.


Accepted Solutions
Solution
‎06-27-2017 09:17 AM
Super User
Posts: 7,824

Re: data manipulation

Use call execute off dataset have:

data have;
input name $ value;
cards;
q        0.2
w       0.3
e        0.4
r        0.5
t        0.6
y       0.11
;
run;

%let n=5;

data _null_;
set have end=done;
if _n_ = 1 then call execute('data want;');
call execute(strip(name) !! ' = ' !! put(value,best.) !! ';');
if done then call execute("do i = 1 to &n; output; end; drop i; run;");
run;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Super User
Super User
Posts: 7,974

Re: data manipulation

Transpose and then set X number of times, though not sure why you would A) want this structure, and B) want to repeat the same data lots of times?

proc transpose data=have out=want;
  by col1;
  var col2;
run;
data want;
  set want want want want want;
run;

Also, when posting test data in the form of a datastep, it should really be runnable, what you post doesn't really help as doesn't show structure.

Contributor
Posts: 62

Re: data manipulation

Many thanks !
When using proc template, get an error msg.

--------------------------------------------
612  proc transpose data=have out=want;
613    by col1;
ERROR: Variable COL1 introuvable.
614    var col2;
615  run;
--------------------------------------------

Also as n is very high, will have to "set want" hundreds of times

 

Regards

Super User
Super User
Posts: 7,974

Re: data manipulation

Sorry, can't find any google search results on:

ERROR: Variable ___ introuvable.

??

 

From your post however, again the question arises, why do you want hundreds of the same data?  This doesn't make any sense to me?  I mean you can do it, just have something like:

data want;
  set sashelp.class (keep=name age);
  do rowid=1 to 10;
    output;
  end;
run;
proc sort data=want;
  by rowid name;
run;
proc transpose data=want out=want;
  by rowid;
  var age;
  id name;
run;

But all that is doing is taking some data and multiplying its storage factor up by 10 for no gain?

Solution
‎06-27-2017 09:17 AM
Super User
Posts: 7,824

Re: data manipulation

Use call execute off dataset have:

data have;
input name $ value;
cards;
q        0.2
w       0.3
e        0.4
r        0.5
t        0.6
y       0.11
;
run;

%let n=5;

data _null_;
set have end=done;
if _n_ = 1 then call execute('data want;');
call execute(strip(name) !! ' = ' !! put(value,best.) !! ';');
if done then call execute("do i = 1 to &n; output; end; drop i; run;");
run;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 62

Re: data manipulation

Posted in reply to KurtBremser

Thanks, works very well with call execute !

Could suggest a smart update if n is the number of rows in data have ?

That is 6 in this case. Always without using iml.

 

Regards 

Super User
Posts: 7,824

Re: data manipulation


DoumbiaS wrote:

Thanks, works very well with call execute !

Could suggest a smart update if n is the number of rows in data have ?

That is 6 in this case. Always without using iml.

 

Regards 


Use _n_ to automatically get the number:

data _null_;
set have end=done;
if _n_ = 1 then call execute('data want;');
call execute(strip(name) !! ' = ' !! put(value,best.) !! ';');
if done then call execute("do i = 1 to " !! put(_n_,best.) !! "; output; end; drop i; run;");
run;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 62

Re: data manipulation

Posted in reply to KurtBremser

Thanks,

B Regards

☑ This topic is solved.

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

Discussion stats
  • 7 replies
  • 134 views
  • 3 likes
  • 3 in conversation