Hi Community,
I have the following data coming through a macro variable, I need to print the data AS IS in the TITLE Statement:
Sample Data:
1Q18-4Q18 CLEARIT UP P25-54 CMT C3
1Q18-4Q18 GIMMY JOHN'S BANDWATCHES SC P18-49 CMDY C3
""BANTAGE 3Q18 UBILOFT ""ASSASIN'S CREED ODYSSEY"" UP M18-34 AMTV C3"
"1Q18-3Q18 PEPPER GROUP ""Terry"" UP P18-34 SPKE C3"
I have worked on the single quote & double quote cases in the IF-ELSE clause.
Commented code is for the DOUBLE Quotes.
Challenges:
1. I am unable to run both the cases at once.
2. How do i solve for the string in 3rd Line, i need to print this in TITLE statement AS IS.
Here is the code which I developed:
options mlogic;
%macro test();
%macro d;%mend d;
%do i=1 %to 3;
proc sql noprint;
select SRCE_DL_NM into :SRCE_DL_NM from data.text where strip(put(sno,8.))="&i.";
;quit;
data dummy;
length SRCE_DL $200.;
SRCE_DL="&SRCE_DL_NM.";
/*SRCE_DL1=&SRCE_DL_NM.;*/
col = CATS("SR_DL",&i.);
x=find(SRCE_DL,"'");
if x > 0 then do;
SR_DL = cats( '"', SRCE_DL,'"');
call symputx(col,%bquote(SR_DL)) ;
end;
/*else IF find(SRCE_DL1,'"') > 0 then do;*/
/* SR_DL = cats( "'", SRCE_DL1,"'");*/
/* call symputx(col,%nrquote(SR_DL));*/
/*end;*/
else call symputx(col,SRCE_DL) ;
run;
%put &&SR_DL&i;
proc print data=sashelp.cars(obs=1);
TITLE &&SR_DL&i;
run;
%end;
%mend();
%test();
Thank you 🙂
I got the solution.
proc sql noprint;
select count(*) into :nrows from data.text;
%put &nrows;
;quit;
%macro test();
%macro d;%mend d;
%do i=1 %to &nrows;
proc sql noprint;
select SRCE_DL_NM into :SRCE_DL_NM from data.text where strip(put(sno,8.))="&i.";
;quit;
%let SRCE_DL = %NRBQUOTE(&SRCE_DL_NM);
proc print data=sashelp.cars(obs=1);
TITLE &SRCE_DL;
RUN;
%end;
%mend();
%test();
Thank you 🙂
I would question why you are doing this in macro? A fundamental concept of SAS is the ability to do by group processing. Just put your title in the data itself and then do:
proc print data=...; by your_title_variable; title '#byval1'; run;
Its really simple. Another method is to call execute from a dataset, avoids all the looping, macro variables etc. Again, simpler coding.
Provide test data in the form of a datastep and what you want to see out from that for more guidance.
Actually i am using it only in the TITLE statement inside a SAS MACRO, PROC Print I have used to see the Result in the SAS EG. So basically whatever the macro variable holds i have to print it using TITLE statement.
Title statements only have relevance in terms of a procedure which produces output...
Macro does not produce output, macro does not execute code etc. Macro is a find and replace system.
I got the solution.
proc sql noprint;
select count(*) into :nrows from data.text;
%put &nrows;
;quit;
%macro test();
%macro d;%mend d;
%do i=1 %to &nrows;
proc sql noprint;
select SRCE_DL_NM into :SRCE_DL_NM from data.text where strip(put(sno,8.))="&i.";
;quit;
%let SRCE_DL = %NRBQUOTE(&SRCE_DL_NM);
proc print data=sashelp.cars(obs=1);
TITLE &SRCE_DL;
RUN;
%end;
%mend();
%test();
Thank you 🙂
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.