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 (December 2004, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 3 Dec 2004 08:38:40 -0800
Reply-To:     Dennis Diskin <diskin@SNET.NET>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Dennis Diskin <diskin@SNET.NET>
Subject:      Re: Macro question
Comments: To: SAS bee <wlv@AIR.ORG>
In-Reply-To:  <59e78f41.0412030803.489ff678@posting.google.com>
Content-Type: text/plain; charset=us-ascii

bee,

You seem to mixing macro code in with dataset where you have: call symput('Num',no); %let Single&i=var&i=%cmpres(&Num); %put Num&i=&Num;

The &NUM does not get set until the datastep executes. I'm not sure exactly what you are trying to do with the %Global SingleN;

You should probably put the %let after the RUN;

Or make the whole thing simpler by:

%let CRN=7; %let inDS=GStudy; %macro MFCS_Single; %global SingleN; %local Num; %local Single&i; %let SingleN=; %do i=1 %to &CRN; DATA _Single&i; set &inds(where=(var&i ge 0) keep=var&i) end=eof; if eof then call symput("Single&i","var&i="||trim(left(put(_N_,8.)))); run; %let SingleN = &SingleN &&single&i ; %end; %Mend MFCS_Single; %MFCS_Single; %put &singleN; run;

SAS bee <wlv@AIR.ORG> wrote: Thank you all for the reponse to my "Counters problem in DATA step"! In fact, it is only part of my coding. After solving it, another issue comes out. The following codes are used to create 7 sub data sets from a data set which contains 7 variables (var1-var7). These sub datasets only contain each variable only when its value is >=0, i.e. _Single&i contains only var&i with positive values. And a macro variable SingleN generated to contain the number of observations in each sub dataset in such a format: var1=12663 var2=12623 var3=12666 var4=12549 var5=12195 var6=12804 var7=12484.

The strange thing is that the SingleN output is like: var1= var2=12663 var3=12623 var4=12666 var5=12549 var6=12195 var7=12804. SAS assigned var1's value to var2, var2's to var3...var6 to var7. Do you know why? Thank you very much!

%let CRN=7; %let inDS=GStudy; %Macro MFCS_Single; %global SingleN; %let SingleN=; %do i=1 %to &CRN; %local Num; %local Single&i; data _Single&i; set &inDS END=lastOBS; If _n_=1 then no=0; If (var&i GE 0) then do; no+1; keep var&i; output; end; If lastOBS then do; call symput('Num',no); %let Single&i=var&i=%cmpres(&Num); %put Num&i=&Num; end; run; %let SingleN=&SingleN &&Single&i; %end; %Mend MFCS_Single; %MFCS_Single;

A SAS bee finally finds her home :) Wendy


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