- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 10-29-2010 03:37 PM
(1978 views)
How to print the cecode that corresponds to &&var&i?
What happens is that i is taking the next value instead of the current value.
say &&var&i for i=1 resolves to 'AMPS' and for i=2 resolves to 'ACOP'. i want to print cecode as 'AMPS' when it reads values from AMPS dataset ,ACOP when it reads values from ACOP dataset in ref library.The records are appended in the set statement and a final dataset vir is created.
%macro cecodes;
data vir;
set
%do i=1 %to &nobs.;
ref.&&var&i
%end;;
cecode=&&var&i;
run;
%mend cecodes;
%cecodes;
What happens is that i is taking the next value instead of the current value.
say &&var&i for i=1 resolves to 'AMPS' and for i=2 resolves to 'ACOP'. i want to print cecode as 'AMPS' when it reads values from AMPS dataset ,ACOP when it reads values from ACOP dataset in ref library.The records are appended in the set statement and a final dataset vir is created.
%macro cecodes;
data vir;
set
%do i=1 %to &nobs.;
ref.&&var&i
%end;;
cecode=&&var&i;
run;
%mend cecodes;
%cecodes;
5 REPLIES 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You are close. try the following untested code in sas9.2 or earlier:
[pre]%macro cecodes;
data vir;
set
%do i=1 %to &nobs.;
ref.&&var&i(in=in&&var&i)
%end;;
%do i=1 %to &nobs.;
%if &i gt 1 %then else;
if in&&var&i then cecode="&&var&i";
%end;
run;
%mend cecodes;
%cecodes [/pre]
A second %DO builds the if-then/else. Notice the double quotes around the constant value for CECODE.
[pre]%macro cecodes;
data vir;
set
%do i=1 %to &nobs.;
ref.&&var&i(in=in&&var&i)
%end;;
%do i=1 %to &nobs.;
%if &i gt 1 %then else;
if in&&var&i then cecode="&&var&i";
%end;
run;
%mend cecodes;
%cecodes [/pre]
A second %DO builds the if-then/else. Notice the double quotes around the constant value for CECODE.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Where is &nobs assigned - also, is it intentional that you have reference to &i outside your %DO loop? Lastly, suggest adding this code to help SAS generate the most diagnostics output for your desk-checking with SAS compilation:
OPTIONS SOURCE SOURCE2 MACROGEN SYMBOLGEN MPRINT /* MLOGIC */;
And, with the above code added, suggest the OP re-post a reply with the SAS-generated log output revealed, not just the code-piece -- presuming the problem is still not solved with additional log diagnostics info.
Scott Barry
SBBWorks, Inc.
OPTIONS SOURCE SOURCE2 MACROGEN SYMBOLGEN MPRINT /* MLOGIC */;
And, with the above code added, suggest the OP re-post a reply with the SAS-generated log output revealed, not just the code-piece -- presuming the problem is still not solved with additional log diagnostics info.
Scott Barry
SBBWorks, Inc.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
PROC SQL;
select codes into:var1-:var20 from cecodes;
select count(*) into:nobs from cecodes;
QUIT;
%put &nobs;
select codes into:var1-:var20 from cecodes;
select count(*) into:nobs from cecodes;
QUIT;
%put &nobs;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
And, so, take this opportunity to debug your SAS program, as suggested, with the additional OPTIONS statement no less.
Scott Barry
SBBWorks, Inc.
Scott Barry
SBBWorks, Inc.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I will look into it.Thanks.