From: xlr82sas on 10 Apr 2010 22:42 Hi SAS-Lers, The real pourpose is to show SAS programmers how they can do' by' processing in a R setting. Note lapply works on R data frame objects which are very close to a SAS datasets. lapply is like the class or by statement in SAS. For cleaner view see http://homepage.mac.com/magdelina/.Public/utl.html utl_tipweb.txt /* T005750 HOW TO IMPLEMENT 'BY' CLAUSE FUNCTIONALITY IN R lapply /* T005210 DROP DOWN TO R IN A DATASTEP FCMP RUN_MACRO GENERAL ANALYSIS OF VARIANCE AND LEAST SQUARES WITHOUT SAS-STA /* Interface with R setup - not a general macro you will have to edit this requires SAS 9.2 and WIN XP */ %rsetup; /* create some data */ data have; input id case1 case2; cards; 1 3 5 1 3 5 1 3 5 1 1 5 1 0 1 2 6 3 2 3 4 2 9 5 2 6 6 2 6 7 2 0 8 3 1 6 3 2 7 3 5 8 3 2 8 ; run; /* proc means data=have sum; class id; run; Here is what I want the output to look like Obs ID CASE1 CASE2 1 1 10 21 2 2 30 33 3 3 10 29 */ data _null_; length pgm $1024; /* max R program length */ call putxpt('have'); /* prep have for R */ /* R CODE */ pgm=compbl(" library(SASxport); library(foreign); x<-read.xport('C:\\utl\\have.xpt'); x; want<-do.call(""rbind"",lapply(split(x, x$ID), function(x) data.frame(sid=max(x$ID), sc1=sum(x$CASE1), sc2=sum(x$CASE2)))); want; write.xport(want,file='C:\\utl\ \want.xpt',autogen.formats=FALSE); "); /* EXECUTE R CODE */ call rxeq(pgm); /* CREATE SAS DATASET FROM R OUTPUT */ call getxpt('want'); run; proc print data=want; run; /* Obs SID SC1 SC2 1 1 10 21 2 2 30 33 3 3 10 29 */ SOAPBOX ON I hope to influence some SAS programmers to consider R for Graphics/ Statistics/Interface to EXCEL.... Also if Enterprise Guide becomes the only editor that SAS will enhance, it may be better to use a R IDE in the future and run your SAS code under the R IDE, sending SAS programs to the server and retrieving SAS log and lists. Gradually you may find yourself doing more and more in R as SAS moves toward SAS-SAP(editors without function keys or command lines, metadata servers, project files in zip files, loss of window functionality). I have decided not to suggest any improvements to the SAS editor, because all improvements will only be made in EG. I remember l asking SAS for X, XX and flip functionality for the old editor years ago, what they did was add inferior similar functionality to the enhanced editor(enhanced editor has no prefix area) and not the old editor. I regret showing how you may be able to run SCL in EG, because I think it took 1 millesecond for SAS to thow a million dollars on the problem and enable EG to run SCL. I wonder when EG will support the datastep debugger? I am aslo concerned about SGF becoming a marketing tool for SAS. There seems to be a lot of confusion about SAS stategic direction. I have no problem with SAS providing tools for non-programmers and IS/IT staffs, ie EG, metatdata servers, project files, DI integration studio.... But SAS should make it clear that these tools will negatively impact an advanced programmers productivity and programmers need client and server functionality. SOAPBOX OFF
From: montura on 12 Apr 2010 12:58 SOAPBOX ON For $200 you can say it yourself. Get an account at businesswire.com and issue your own press release. Presto. No more confusion. I'm not really sure about who exactly is confused/bamboozled/screwed up?
|
Pages: 1 Prev: Why %unistats, %npcttab and Spectre-Clinical is FREE Next: Top R packages for SAS programmers |