[英]sas macro do loop and ampersand to subset dataset
在下面的宏中,如何在數據步驟中自動從sashelp.cars中選擇汽車。 我認為這涉及到&號%let dsn =&inDsn; ....
%macro subset_by_make (dsn=,carList=);
%let car_n = %sysfunc(countw(&carList, ' '));
%do i = 1 %to &car_n;
%let make = %scan (&carList, &i, ' ');
data cars_&make;
set sashelp.cars(where = (make = "&make"));
run;
proc print data=cars_&make;
run;
%end;
%mend subset_by_make;
%subset_by_make(dsn=sashelp.cars, carList= Acura Toyota);
希望對Maggie有所幫助
如果您只想打印出按make分組的汽車數據集,則這里根本不需要任何宏代碼:
proc sort data = sashelp.cars out = cars;
by make;
run;
proc print data = cars;
where make in ('Acura','Toyota');
by make;
run;
麗莎,對不起,我的問題令人困惑。 我想從sashelp.cars創建各種名為cars_acura,cars_toyota等的數據集
下面,我想我已經找到了解決方案。 謝謝大家的幫助!
%macro subset_by_make (lib=,inDsn=,carList=);
%let car_n = %sysfunc(countw(&carList, ' '));
%do i = 1 %to &car_n %by 1;
%let make = %scan (&carList, &i, ' ');
title "dataset: &inDsn._&make";
data &inDsn._&make;
set &lib..&inDsn(where = (make = "&make"));
run;
proc print data=cars_&make;
run;
%end;
%mend subset_by_make;
%subset_by_make(lib=sashelp,inDsn=cars,carList= Acura Toyota);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.