Hi,,all;
I tried to write some macro statements.but they did not work and I can not find the mistakes,here are the codes.Thanks.
%macro T71122;
proc sort data=test2;
by OBS;
run;
data test3;
set test2;
if obs=1 then delete;
run;
data test3;
set test3;
obs=obs-1;
run;
proc sql;
select distinct AMTEST into: AMTESTlist separated by ":" from test3 ;
run;
quit;
%let num=1;
%do %while(%scan(&AMTESTlist.,&num.,%str(:)) NE %str());
%let AMTESTtest=%scan(&AMTESTlist.,&num.,%str(:));
%let num=%eval(&num.+1);
%end;
%mend;
%T71122;
The code seems fine,but there is issue with the data i.e. in AMTEST there is text as '榓-
'
the special characters concatenated to HCV and these special characters need to be removed using compress function and it will resolve the issue.
%macro T71122;
data test3;
set test.test2 (ENCODING=WLATIN1);
if obs=1 then delete;
run;
data test3;
set test3;
obs=obs-1;
run;
proc sql;
select distinct compress(AMTEST,'?榓-') into: AMTESTlist separated by ":" from test3 ;
quit;
%put &AMTESTlist.;
%let num=1;
%do %while(%scan(&AMTESTlist.,&num.,%str(:)) NE %str());
%let AMTESTtest=%scan(&AMTESTlist.,&num.,%str(:));
%let num=%eval(&num.+1);
%put #
%end;
%mend;
options mprint;
%T71122;
Macro variables have scope. If created in a macro, they are local to that macro and vanish as soon as the macro stops executing.
You can simplify the macro loop by using the automatic macro variable sqlobs:
%do num = 1 %to &sqlobs.;
%let AMTESTtest=%scan(&AMTESTlist.,&num.,:);
%end;
If you have further problems, post the log by using the {i} button.
The code seems fine,but there is issue with the data i.e. in AMTEST there is text as '榓-
'
the special characters concatenated to HCV and these special characters need to be removed using compress function and it will resolve the issue.
%macro T71122;
data test3;
set test.test2 (ENCODING=WLATIN1);
if obs=1 then delete;
run;
data test3;
set test3;
obs=obs-1;
run;
proc sql;
select distinct compress(AMTEST,'?榓-') into: AMTESTlist separated by ":" from test3 ;
quit;
%put &AMTESTlist.;
%let num=1;
%do %while(%scan(&AMTESTlist.,&num.,%str(:)) NE %str());
%let AMTESTtest=%scan(&AMTESTlist.,&num.,%str(:));
%let num=%eval(&num.+1);
%put #
%end;
%mend;
options mprint;
%T71122;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.