簡體   English   中英

努力在SAS中傳遞宏值

[英]Struggling with passing macro value in SAS

本來,我有這樣的代碼。

data newFile;
set File;
   If Gender NE 'Female' then delete;
   If Group NE 10 then delete;
   If Age GT 30 then delete;
run;

它工作正常。 但是我希望能夠從頂部更改這些條件,因此我添加了宏變量。 到目前為止,我有這個

&let macGender = 'Female';
&let macGroup = 10;
&let macAge = 30;

data newFile;
set File;
   If Gender NE &macGender then delete;
   If Group NE &macGroup then delete;
   If Age GT &macAge then delete;    
run;

它似乎不像原始代碼那樣工作。 我什至嘗試過這樣的事情

您需要%let而不是&let

%let是用於將值分配給宏變量的宏語句。

&let是對您(可能)尚未創建的宏變量的引用。

在您的宏聲明中用%號代替&在您的前面讓let聲明並消除女性的引號。

將這些引號放在實際的宏周圍。

例如

%let macGender =女性;

如果是Gender NE“&macGender”。 然后刪除;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM