Here is the example. I have a macro and proc iml. In the PROC IML, after the loop ends I want five different means but I am not getting that. %macro hello(X); use &dataset; read all var{&X} into A; m=mean(A); print m; %mend hello; proc iml; do i = 1 to 5; X=randnormal(10,0,1); firstcol=X[,1]; create newdata var{firstcol}; append; close; %let dataset=newdata; %hello(firstcol); call delete(dataset); end; quit;
The call
X=randnormal(10,0,1);
creates a vector that has 10 obs and 1 var.
Also, every time you run the CREATE statement, it overwrites the previous data set.
If you want a data set that has 5 columns, then put the variables into a matrix that has 5 cols and write the matrix to a data set:
proc iml;
X=randnormal(10,{0 0 0 0 0},I(5));
varNames = {X1 X2 X3 X4 X5};
print X[colname=varNames];
create newdata from X[colname=varNames];
append from X;
close;
quit;
proc print;run;
This was the example that I created to ask question here. What I have is more complicated. But the idea is same. What I want is in each loop when I call the macro I should be getting different result.
The call
X=randnormal(10,0,1);
creates a vector that has 10 obs and 1 var.
Also, every time you run the CREATE statement, it overwrites the previous data set.
If you want a data set that has 5 columns, then put the variables into a matrix that has 5 cols and write the matrix to a data set:
proc iml;
X=randnormal(10,{0 0 0 0 0},I(5));
varNames = {X1 X2 X3 X4 X5};
print X[colname=varNames];
create newdata from X[colname=varNames];
append from X;
close;
quit;
proc print;run;
I am still not able to get what I am looking for. I tried this code.
%macro hello(X); use &dataset; read all var{&X} into A; m=mean(A); print m; %mend hello; proc iml;
z=j(5,1,0);
do i = 1 to 5;
X=randnormal(10,0,1);
varNames={X1};
print X[colname=varNames];
create newdata from X[colname=varNames];
append from X;
close;
%let dataset=newdata;
%hello(X1);
z[i]=m[1];
end;
quit;
Following is the error message:
@themanoj20080 wrote:
I am still not able to get what I am looking for. I tried this code.
Then perhaps it is time to show what some data similar to what you are actually starting with and what the result for that starting data should be. BOTH, begin and end.
Showing code that doesn't work does not get us a lot closer to an actual solution. Showing the desired solution for actual data allows better understanding of the actual issue.
Your second posting contains the same program as your first post. You did not incorporate my suggestion.
Actually I got it to work. I just had to put "call delete(my data)" at the end. Thank you for your suggestion.
Need to add "call delete(mydata)" at the end. And it works.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.
Find more tutorials on the SAS Users YouTube channel.