- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
issue with output:
i m trying to giving output as per condition, but its giving all observation to all created dataset.
my desired result is getting by existing code but for that i need to create addition dataset "X". I dont want to create that X dataset.
how can i prevent process to put observation to all.
my code is:
DATA CONTROL;
INPUT BANKCODE $1-6 PRODCODE $9-10 COND $13-36;
DATALINES;
HDFC HL DELAY>10
HDFC CC DELAY<10
ICICI ML DEFAULT=100
ICICI CC DEFAULT<10 AND DELAY<10
IDBI ML WRITE_OFF =10
IDBI CC DELAY<20
;
RUN;
PROC PRINT; RUN;
PROC SQL NOPRINT;
Select bankcode, prodcode, cond into : banklist separated by "|" ,: prodlist separated by "|" ,: condlist separated by "|" from control;
%let ct = &sqlobs;
QUIT;
%put &banklist &prodlist &condlist &ct;
DATA MASTER;
INPUT BANKCODE $1-6 PRODCODE $9-10 DELAY 13-14 DEFAULT 17-18 WRITE_OFF 21-24;
DATALINES;
HDFC CC 5 1 12
ICICI HL 6 4 100
IDBI ML 2 3 20
;
RUN;
PROC PRINT; RUN;
option mlogic symbolgen macrogen;
%macro test();
data hdfc icici idbi x;
set master;
%do i =1 %to &ct;
%let bname=%scan(%bquote(&banklist),&i,%str(|));
%let pname=%scan(%bquote(&prodlist),&i,%str(|));
%let cname=%scan(%bquote(&condlist),&i,%str(|));
%if (bankcode="&bname") and (prodcode="&pname") and (&cname) %then
%do;
*status= "&cname.";
status=%substr(%bquote(&cname),1,%sysfunc(ANYPUNCT(%bquote(&cname)))-1);
output &bname. ;
%end;
%end;
output x;
run;
%mend;
%test;
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
There are several points here. Firstly your test dataset CONTROL is not being created as you think it is. The variable BANKCODE for instance is reading 6 characters in , so HDFC H for first row. This doesn't match anything in the master table.
Then there is the problem that you are mixing macro code with datastep code.
The %if construct is a macro command, it is there to generate code conditionally - i.e. it isn't part of the datastep. Thus saying %if a datastep variable called bankcode="&bname."... - this is invalid, as the text "bankcode" != whatever &bname resolves to. Bank code is part of the datastep and the datastep syntax, % macro commands are part of the macro compiler. Think of the macro compiler as a text replace function, not part of the SAS code.
Now you are looking to do certain conditions on the dataset correct. So try the following:
data control;
length bankcode $6 prodcode $2 cond $200;
infile datalines dlm=",";
input bankcode $ prodcode $ cond $;
datalines;
HDFC,HL,DELAY>10
HDFC,CC,DELAY<10
ICICI,ML,DEFAULT=100
ICICI,CC,DEFAULT<10 AND DELAY<10
IDBI,ML,WRITE_OFF =10
IDBI,CC,DELAY<20
;
run;
data master;
length bankcode $6 prodcode $2;
infile datalines dlm=",";
input bankcode $ prodcode $ delay default write_off;
datalines;
HDFC,CC,5,1,12
ICICI,HL,6,4,100
IDBI,ML,2,3,20
;
run;
data _null_;
set control end=last;
if _n_=1 then call execute('data hdfc icici idbi; set master;');
call execute(' if bankcode="'||strip(bankcode)||'" and prodcode="'||strip(prodcode)||'" and '||strip(cond)||' then output '||strip(bankcode)||';');
if last then call execute(';run;');
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I am not following your logic or example. If you don't want to save X then drop that from here: data hdfc icici idbi x;
And drop this: output x;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Apology for not being clear.
Resultant with corrent code is 0obs is correct.
If i will remove content related with data set x, resultant will be 3 obs to each dataset which is wrong, i dont want that and i also dont want to creat dataset x. I hope i tried to explain my best
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
There are several points here. Firstly your test dataset CONTROL is not being created as you think it is. The variable BANKCODE for instance is reading 6 characters in , so HDFC H for first row. This doesn't match anything in the master table.
Then there is the problem that you are mixing macro code with datastep code.
The %if construct is a macro command, it is there to generate code conditionally - i.e. it isn't part of the datastep. Thus saying %if a datastep variable called bankcode="&bname."... - this is invalid, as the text "bankcode" != whatever &bname resolves to. Bank code is part of the datastep and the datastep syntax, % macro commands are part of the macro compiler. Think of the macro compiler as a text replace function, not part of the SAS code.
Now you are looking to do certain conditions on the dataset correct. So try the following:
data control;
length bankcode $6 prodcode $2 cond $200;
infile datalines dlm=",";
input bankcode $ prodcode $ cond $;
datalines;
HDFC,HL,DELAY>10
HDFC,CC,DELAY<10
ICICI,ML,DEFAULT=100
ICICI,CC,DEFAULT<10 AND DELAY<10
IDBI,ML,WRITE_OFF =10
IDBI,CC,DELAY<20
;
run;
data master;
length bankcode $6 prodcode $2;
infile datalines dlm=",";
input bankcode $ prodcode $ delay default write_off;
datalines;
HDFC,CC,5,1,12
ICICI,HL,6,4,100
IDBI,ML,2,3,20
;
run;
data _null_;
set control end=last;
if _n_=1 then call execute('data hdfc icici idbi; set master;');
call execute(' if bankcode="'||strip(bankcode)||'" and prodcode="'||strip(prodcode)||'" and '||strip(cond)||' then output '||strip(bankcode)||';');
if last then call execute(';run;');
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks, it makes much easier way.