I haven't worked with macros in awhile, so please bear with me. I am wanting to simulate some data using specific seed numbers.I have 20 pairs of values for seed1 and seed2. The following is what I have sketched out for one pair of seed1 and seed2 values, but I don't know how to create a loop that runs through the set of 20 values (do while?). appreciate some pointers. thanks jm
%macro xone(seed1= seed2=);
data samples;
do samp = 1 to 100;
do t = 1 to 100;
u = rannor(&seed1)*5;
x = 100 + 3*rannor(&seed2);
y = 10 + 0.5*x + u;
output;
end ;
end;
run;
%mend;
%xone(seed1=1234, seed2=4567);
Use call execute:
data _null_;
input seed1 seed2;
call execute('%xone(seed1='!!put(seed1,best.)!!',seed2='!!put(seed2,best.)!!');');
cards;
1234 4567
;
run;
Kurt - thank you very much. It worked great. Each pair of seed1, seed2 has a student's name associated with it. I want to add in the student's name and have the program print out the seed1, seed2 and name as well as the proc means for the data that are generated for each student. In the code below, I used title &seed1 &seed2 before the proc mean and it worked (altho I am sure there is probably a better way), but when I add in name it doesn't print the name. I made a number of attempts, but am quite unfamiliar with call execute . any ideas? thanks again!
options ls=78 formdlim='*' nodate nonumber nolabel;
ods listing;
%macro xone(seed1,seed2,name);
data samples;
do samp = 1 to 10;
do t = 1 to 100;
u = rannor(&seed1)*5;
x = 100 + 3*rannor(&seed2);
y = 10 + 0.5*x + u;
output;
end ;
end;
run;
title &seed1 &seed2 &name;
proc means;
%mend;
data _null_;
input seed1 seed2 name $;
call execute('%xone(seed1='!!put(seed1,best.)!!',seed2='!!put(seed2,best.)!!',name);');
cards;
1234 4567 Doyle
1117 7111 Boyce
;
run;
I think you need a slight change:
call execute('%xone(seed1='!!put(seed1,best.)!!',seed2='!!put(seed2,best.)!!','!!name!!');');
Yes, this worked great. thanks again
name='!!name!!'
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 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.