LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (May 2005, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Sun, 15 May 2005 00:00:01 +0000
Reply-To:   iw1junk@COMCAST.NET
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Ian Whitlock <iw1junk@COMCAST.NET>
Subject:   Re: Do you recommed this source ..
Comments:   cc: Robbins <robbins@O2.PL>

Rob,

Others can teach you enough macro to get you looping, but I would suggest it is worth learning to think in SAS first.

For example, with the problem you gave it is probably better to do something like

DATA DAT; do gp = 1 to 10 ; DO I=1 TO 100; X=RANNOR(0); Y=RANNOR(0); OUTPUT; END; end ; run ;

proc sort data = dat ; by gp ; run ;

*** use PROC CORR to get Pearson r, results as SAS dataset PEARSON;

PROC CORR DATA=DAT NOPRINT OUTP=PEARSON (keep= _name_ y gp where = ( upcase(_name_) = "X" )) ; by gp ; VAR X Y; RUN;

I made my loops smaller than you asked for becasue this code was run on the LE version with a 1000 record limit.

If you must loop then I suggest you use a simpler technique. I added

Proc append base = summary data = pearson ; run ;

to the bottom of your code, since it would be pointless to loop without some means of collecting the data generated. I stored the code in C:\JUNK\LOOPTEST.SAS. Finally I ran the following code

data _null_ ; do i = 1 to 10 ; call execute ( '%inc "c:\junk\looptest.txt" ;' ) ; end ; run ;

proc print data = summary ; var corr ; run ;

to get what you wanted on a smaller scale.

Finally, if you have to start with the full macro language, "The Little SAS Book" has a chapter that is enough to get you started. Incidentally, the authors gave a cheerful beginning tutorial on macro at SUGI 29. (I heard the presentation and liked it, but did not read the paper.) I located the paper using

http://www.lexjansen.com/sugi/index.htm

with the search term "macro slaughter". It was the first paper to pop up. The term "beginning macro" turned up many different papers. Look for the ones that indicate they are general beginning tutorials.

Ian Whitlock ================== Date: Sat, 14 May 2005 22:12:31 +0200 Reply-To: Robbins <robbins@O2.PL> Sender: "SAS(r) Discussion" From: Robbins <robbins@O2.PL> Organization: Wroclaw University of Technology, Poland Subject: Re: Do you recommed this source .. Comments: To: sas-l I'm immensely indebted to all for comments and suggestion. I should explain why I intend to learn macros. I wrote programs in MATLAB. But statistics there is very poor. Also , because my university buy SAS licence I decided to quit writing codes in MATLAB and I choose SAS. In SAS I would like to write my own code, as well - e.g. simulation (Monte Carlo). But I noticed that SAS does not allow to write code like this: do i=1 to 1000; proc something; ....... run; proc something; ....... proc something; ....... run; run; end; It is immposible to nested proc, data and so on. I bought book: SAS for Monte Carlo Studies (Fan, Felsovalyi, Silvo, Keenan). But there are only macros.I tried to modify code to simulate 2 variables X and Y from independent normal pdf. Next I count Pearson's correlation. But I can't to figure out how to repeat this 200 times to get 200 Pearson's correl. Therefore I thought that I should learn macro. Does anybody know how to do it. Program is (it's a pity that I can't write: repeat 200 my program end;) DATA DAT; DO I=1 TO 1000; X=RANNOR(0); Y=RANNOR(0); OUTPUT; END; *** use PROC CORR to get Pearson r, results as SAS dataset PEARSON; PROC CORR DATA=DAT NOPRINT OUTP=PEARSON; VAR X Y; RUN; DATA PEARSON; SET PEARSON; IF _NAME_='X'; CORR=Y; KEEP CORR; run; Thank you vary much Rob


Back to: Top of message | Previous page | Main SAS-L page