<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: retain the variable name in the macro in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/retain-the-variable-name-in-the-macro/m-p/583163#M13931</link>
    <description>&lt;P&gt;You cannot "delete" a missing value, as it is already "nothing". What you can delete, are whole observations (=rows) that contain missing values, or you could drop variables (=columns) from the dataset altogether if you find they contain certain values (or only missing values).&lt;/P&gt;
&lt;P&gt;What of these options you want to do will determine the code.&lt;/P&gt;</description>
    <pubDate>Thu, 22 Aug 2019 13:14:54 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2019-08-22T13:14:54Z</dc:date>
    <item>
      <title>retain the variable name in the macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/retain-the-variable-name-in-the-macro/m-p/583078#M13917</link>
      <description>&lt;P&gt;Hi guys,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm a new sas user and I wanna learn somethings from you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;is any possible that I retain the variables in the new variable as like the list, step by step, for example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have four variables as below:&lt;/P&gt;&lt;P&gt;dep = var1,&amp;nbsp;var2,&amp;nbsp;var3,&amp;nbsp;var4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The Macro I wrote&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;%do i=1 %to %sysfunc(countw(&amp;amp;dep));&lt;/DIV&gt;&lt;DIV&gt;%let dep_nxt = %scan(&amp;amp;dep, &amp;amp;i);&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;data dset_temp; set &amp;amp;dset; if &amp;amp;dep_nxt =. then delete; run; &amp;nbsp;*(I wanna clean each independent variables, not cleaning all at same time);&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;P&gt;first times : new_dep = var1_name&amp;nbsp;&lt;/P&gt;&lt;P&gt;second times : new_dep= var1_name var2_name&lt;/P&gt;&lt;P&gt;third times : new_dep = var1_name var2_name&amp;nbsp;var2_name&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;and there is a space between each name&lt;/P&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;thank you very much&lt;/DIV&gt;</description>
      <pubDate>Thu, 22 Aug 2019 07:19:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/retain-the-variable-name-in-the-macro/m-p/583078#M13917</guid>
      <dc:creator>RayZ</dc:creator>
      <dc:date>2019-08-22T07:19:01Z</dc:date>
    </item>
    <item>
      <title>Re: retain the variable name in the macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/retain-the-variable-name-in-the-macro/m-p/583079#M13918</link>
      <description>&lt;P&gt;I don't see any value in running the data step repeatedly. Do it in one run:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dep=var1 var2 var3 var4;

%macro delete_deps(indata=,outdata=,depvars=);

data &amp;amp;outdata.;
set &amp;amp;indata.;
%do i = 1 %to sysfunc(countw(&amp;amp;depvars.));
  %let dep_single=%scan(&amp;amp;depvar2.,&amp;amp;i.);
  if &amp;amp;dep_single. = . then delete;
%end;
run;

%mend;

%delete_deps(indata=xxxx,outdata=yyyy,depvars=&amp;amp;dep.)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 22 Aug 2019 07:23:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/retain-the-variable-name-in-the-macro/m-p/583079#M13918</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-08-22T07:23:48Z</dc:date>
    </item>
    <item>
      <title>Re: retain the variable name in the macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/retain-the-variable-name-in-the-macro/m-p/583080#M13919</link>
      <description>&lt;P&gt;What exactly do you mean by saying "I wanna clean each independent variables, not cleaning all at same time"?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The delete statement removes observations not variables.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Aug 2019 07:33:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/retain-the-variable-name-in-the-macro/m-p/583080#M13919</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-08-22T07:33:57Z</dc:date>
    </item>
    <item>
      <title>Re: retain the variable name in the macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/retain-the-variable-name-in-the-macro/m-p/583153#M13927</link>
      <description>&lt;P&gt;As a new user, it looks like you are making some progress here.&amp;nbsp; But there are still issues that you need to grasp.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let's start with your original question.&amp;nbsp; If you want to collect names into &amp;amp;NEW_DEP, here is the idea of how you would do it:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let new_dep=;

%do i=1 %to %sysfunc(countw(&amp;amp;dep));
   %let dep_nxt = %scan(&amp;amp;dep, &amp;amp;i);
   %let new_dep = &amp;amp;new_dep &amp;amp;dep_nxt;
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;DIV&gt;Beyond that, though, here are a few issues you will need to contend with.&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;You claim that you wrote a macro.&amp;nbsp; But the code you posted isn't a macro.&amp;nbsp; There is no %MACRO statement, no %MEND statement.&amp;nbsp; There is no %END statement to match the %DO statement.&amp;nbsp; So you have pieces of a macro, but it isn't a macro yet.&amp;nbsp; Perhaps you posted only a few statements from your code?&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;Next, you are trying to go through some trouble to remove commas to get the equivalent of:&lt;/DIV&gt;
&lt;DIV&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dep = var1, var2, var3, var4;
%let new_dep = var1 var2 var3 var4;&lt;/CODE&gt;&lt;/PRE&gt;
It would be much simpler (and probably just as easy as what you are doing now) to get rid of the commas when creating &amp;amp;DEP.&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;Next, consider what would happen if your macro actually worked.&amp;nbsp; SAS would see these statements:&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dset_temp; set &amp;amp;dset; if var1 =. then delete; run; 
data dset_temp; set &amp;amp;dset; if var2 =. then delete; run; 
data dset_temp; set &amp;amp;dset; if var3 =. then delete; run; 
data dset_temp; set &amp;amp;dset; if var4 =. then delete; run; &lt;/CODE&gt;&lt;/PRE&gt;
Each time the %DO loop iterates, it reads from your incoming data set and REPLACES DSET_TEMP.&amp;nbsp; There is only one output data set, and the final contents of DSET_TEMP reflect VAR4 only.&amp;nbsp; You could easily account for this by generating the equivalent of:&lt;/DIV&gt;
&lt;DIV&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data var1; set &amp;amp;dset; if var1 =. then delete; run; 
data var2; set &amp;amp;dset; if var2 =. then delete; run; 
data var3; set &amp;amp;dset; if var3 =. then delete; run; 
data var4; set &amp;amp;dset; if var4 =. then delete; run; &lt;/CODE&gt;&lt;/PRE&gt;
Give the output data set a new name each time through the %DO loop.&amp;nbsp; And it's easy to do, since you already have a macro variable that contains such a name.&amp;nbsp; Just use:&lt;/DIV&gt;
&lt;DIV&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data &amp;amp;dep_nxt; set &amp;amp;dset; if &amp;amp;dep_nxt =. then delete; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;DIV&gt;Finally, note that you are reading the incoming data set four times.&amp;nbsp; You could combine that into one DATA step and read the incoming data only once&amp;nbsp; It would require changing the generated SAS code to this.&lt;/DIV&gt;
&lt;DIV&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data var1 var2 var3 var4;
set &amp;amp;dset;
if var1 &amp;gt; . then ouput var1;
if var2 &amp;gt; . then output var2;
if var3 &amp;gt; . then output var3;
if var4 &amp;gt; . then output var4;
run;&lt;/CODE&gt;&lt;/PRE&gt;
For now, I'll leave that as an exercise for you to solve, using macro language.&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Thu, 22 Aug 2019 12:49:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/retain-the-variable-name-in-the-macro/m-p/583153#M13927</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-08-22T12:49:02Z</dc:date>
    </item>
    <item>
      <title>Re: retain the variable name in the macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/retain-the-variable-name-in-the-macro/m-p/583160#M13929</link>
      <description>&lt;P&gt;my English is not well &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It means that&amp;nbsp;I would delete the missing value in each variable(column) before I put the variable into the regression. ^^&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Aug 2019 13:10:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/retain-the-variable-name-in-the-macro/m-p/583160#M13929</guid>
      <dc:creator>RayZ</dc:creator>
      <dc:date>2019-08-22T13:10:46Z</dc:date>
    </item>
    <item>
      <title>Re: retain the variable name in the macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/retain-the-variable-name-in-the-macro/m-p/583162#M13930</link>
      <description>&lt;P&gt;Yes~~~!! Thank you very much.&lt;/P&gt;&lt;P&gt;I really wanna learn how to build it in sas ^^&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am very new in using SAS, and thanks for all of your kindly help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Aug 2019 13:14:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/retain-the-variable-name-in-the-macro/m-p/583162#M13930</guid>
      <dc:creator>RayZ</dc:creator>
      <dc:date>2019-08-22T13:14:01Z</dc:date>
    </item>
    <item>
      <title>Re: retain the variable name in the macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/retain-the-variable-name-in-the-macro/m-p/583163#M13931</link>
      <description>&lt;P&gt;You cannot "delete" a missing value, as it is already "nothing". What you can delete, are whole observations (=rows) that contain missing values, or you could drop variables (=columns) from the dataset altogether if you find they contain certain values (or only missing values).&lt;/P&gt;
&lt;P&gt;What of these options you want to do will determine the code.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Aug 2019 13:14:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/retain-the-variable-name-in-the-macro/m-p/583163#M13931</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-08-22T13:14:54Z</dc:date>
    </item>
  </channel>
</rss>

