Hi to all,
Using only array statements or a call execute statement, is it possible to do this :
data have;
input a1-a10;
cards;
.101 .201 .3 .4 .5 .6 .7 .8 .9 .10 .11 .12 .13 .14 .15 .16 .17 .18 .19 .20 .21
;
data want;
input a1-a7;
cards;
.101 .4 .7 .10 .13 .16 .19
.201 .5 .8 .11 .14 .17 .20
.3 .6 .9 .12 .15 .18 .21
;run;
Regards
Here is another way using arrays:
data have;
input a1-a21;
cards;
.101 .201 .3 .4 .5 .6 .7 .8 .9 .10 .11 .12 .13 .14 .15 .16 .17 .18 .19 .20 .21
;
data want (drop=_:);
set have (rename=(a1-a21=_a1-_a21));
array all(*) _a1-_a21;
array part(7) a1-a7;
do _i=1 to 3;
_k=0;
do _j=_i to dim(all) by 3;
_k+1;
part(_k)=all(_j);
end;
output;
end;
run;
Art, CEO, AnalystFinder.com
@DoumbiaS wrote:
Hi to all,
Using only array statements or a call execute statement, is it possible to do this :
Why is there a need to place restrictions on what elements of SAS can be used? Is this a homework problem?
I could use a proc sql but I think that It will use Lots of resources with large data. But I welcome anything. Thanks
Regards
Your "data have" statement is wrong, it doesn't read the complete data. Is there some sort of logic behind the request, as taking a bunch of variables and outputting a gourp to each line doesn't make any sense without some sort of identifiers. Providing a good example of the data will likely solve this.
Edit, I mean from this random logic, this would work:
data want (keep=col:);
set have (rename=(a1=col1 a4=col2 a7=col3 a10=col4 a12=col5))
have (rename=(a2=col1...))
have (rename=(a3=col1...));
run;
Note you might need a keep on each of those datasets, haven't tried the code, just showing that setting the data three times with renames would work.
Here is another way using arrays:
data have;
input a1-a21;
cards;
.101 .201 .3 .4 .5 .6 .7 .8 .9 .10 .11 .12 .13 .14 .15 .16 .17 .18 .19 .20 .21
;
data want (drop=_:);
set have (rename=(a1-a21=_a1-_a21));
array all(*) _a1-_a21;
array part(7) a1-a7;
do _i=1 to 3;
_k=0;
do _j=_i to dim(all) by 3;
_k+1;
part(_k)=all(_j);
end;
output;
end;
run;
Art, CEO, AnalystFinder.com
data have;
input a1-a21;
cards;
.101 .201 .3 .4 .5 .6 .7 .8 .9 .10 .11 .12 .13 .14 .15 .16 .17 .18 .19 .20 .21
;
data want;
set have;
array ar(*) a:;
do _n_=1 to dim(ar);
b=ar(_n_);
index+1;
output;
if mod(index,3)=0 then index=0;
end;
drop a:;
run;
proc sort data= want out=want1;
by index;
run;
proc transpose data=want1 out=want2(drop=index b _NAME_) ;
by index;
var b;
run;
Here another coding variant using arrays.
data have(drop=_:);
array _vars {7,3} 8;
infile datalines dlm=' ' truncover;
input _vars[*];
array a {7} 8;
do _d2=1 to dim(_vars,2);
do _d1=1 to dim(_vars,1);
a[_d1]=_vars[_d1,_d2];
end;
output;
end;
datalines;
.101 .201 .3 .4 .5 .6 .7 .8 .9 .10 .11 .12 .13 .14 .15 .16 .17 .18 .19 .20 .21
;
run;
So sorry for my long absence.
Of course it was a copy - paste error about a10 instead of a21.
Such I use large dataset with great large number of variables, optimize is efficient.
Thanks to all for responses.
Regards
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.