生活随笔
收集整理的這篇文章主要介紹了
SAS 宏
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
sas宏語言詳細教程 所有的變量值都只能是字符
data sales2001;set sashelp.orsales;if year=2001;
run;
proc print data=sales2001;
title 'sales in 2001';
footnote1 'create-2017';/*腳注,標題,對表進行修改編輯,可以直接寫footnote,如果有多個腳注,可以加1,加2*/
footnote2 'on then win system using sas 9.4';
run;
/*使用宏語言改寫*/%let year=2001;/*定義了宏變量YEAR,并且賦值2001,
在后面使用&year來代替2001*/
data sales&year;set sashelp.orsales;if year=&year;
run;
proc print data=sales&year;
title 'sales in &year';/*這里有問題*/
footnote1 'create-2017';/*腳注,標題,對表進行修改編輯,可以直接寫footnote,如果有多個腳注,可以加1,加2*/
footnote2 'on then win system using sas 9.4';
run;%let town=detroit;
data city;input city $ state $;
cards;
detroit mi
chicago il
;
run;
data city2;set work.city;
where city='detroit';
run;%let town=detroit;
data city;input city $ state $;
cards;
detroit mi
chicago il
;
run;
data city2;set work.city;
where city="&town";/*detroit是city這個列的一個值,所以要用字符串,因此如果要用宏變量,
也要加引號,需要加雙引號,單引號不對,后面寫了單引號內的宏變量不會被解析,雙引號內的宏變量才會被解析*/
run;