BookmarkSubscribeRSS Feed
doylejm
Fluorite | Level 6

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);

4 REPLIES 4
Kurt_Bremser
Super User

Use call execute:

data _null_;
input seed1 seed2;
call execute('%xone(seed1='!!put(seed1,best.)!!',seed2='!!put(seed2,best.)!!');');
cards;
1234 4567
;
run;
doylejm
Fluorite | Level 6

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;

doylejm
Fluorite | Level 6

Yes, this worked great. thanks again

 

name='!!name!!'

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 2360 views
  • 0 likes
  • 2 in conversation