SAS Advanced programming 정리- SAS Macro (10)

Hoya Jaeho Lee·2022년 4월 18일
0

SAS Advanced programming

목록 보기
10/17

Chapter 10 -Processing Macro Variables at Execution Time

Using CALL SYMPUT to Create Macro Variables****

options symbolgen pagesize=30;

%let crsnum=3;
data revenue;
set sasuser.all end=final;
where course_number=&crsnum;
total+1;
if paid='Y' then paidup+1;
if final then do;
if paidup<total then do;
call symput('foot','Some Fees Are Unpaid');
end;
else do;
call symput('foot','All Students Have Paid');
end;
end;
run;

proc print data=revenue;
var student_name student_company paid;
title "Payment Status for Course &crsnum";
footnote "&foot";
run;

Referencing Macro Variables Indirectly

options symbolgen;

data null;
set sasuser.courses;
call symput(course_code, trim(course_title));
run;

%let crsid=C005;
proc print data=sasuser.schedule noobs label;
where course_code="&crsid";
var location begin_date teacher;
title1 "Schedule for &&&crsid";
run;
%let crsid=C002;
proc print data=sasuser.schedule noobs label;
where course_code="&crsid";
var location begin_date teacher;
title1 "Schedule for &&&crsid";
run;

코드 설명:

title1 "Schedule for &&&crsid";
왜 3개가 참조 되었는지!!
두번이상 참조 되어서 3개로 표기:)

Using SYMGET to Obtain Macro Variable Values

data teachers;
set sasuser.register;
length Teacher $ 20;
teacher=symget('teach'||left(course_number));
run;

proc print data=teachers;
var student_name course_number teacher;
title1 "Teacher for Each Registered Student";
run;

Creating Macro Variables with the INTO Clause

proc sql noprint;
select course_code, location, begin_date format=mmddyy10.
into :crsid1-:crsid3,
:place1-:place3,
:date1-:date3

from sasuser.schedule
where year(begin_date)=2002
order by begin_date;
quit;

또 다른 예시

proc sql noprint;
select distinct location into :sites separated by ' '
from sasuser.schedule;
quit;

proc means data=sasuser.all sum maxdec=0;
var fee;
title1 'Total Revenue';
title2 "from Course Sites: &sites";
run;

call symput: string의 형태가 아님, 위에 경우와 구분할 것
string 형태가 아닌 경우:
a series of macro variables whose names are values of the data set variable Course_code, then indirectly references
one of those macro variables in a later step

profile
Biostatistics researcher Github: https://github.com/hoyajhl

0개의 댓글