<?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: Keeping variables from datasets in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Keeping-variables-from-datasets/m-p/625385#M20242</link>
    <description>&lt;P&gt;1. Import your Excel file, I'm going to assume you know how to do this.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. Create a list of the variables using a macro variable&lt;/P&gt;
&lt;P&gt;3. Use the macro variable&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It really does depend on how the 'empty' variable data set is structured, though. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select varName into :keep_list separated by " "
from importFromExcel;
quit;

data want;
set t1 (keep = &amp;amp;keep_list)
      t2 (keep = ID ....other variables *optional*);

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/312519"&gt;@JayceWaylon&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P class="_1qeIAgB0cPwnLhDF9XSiJM"&gt;Is there a way to keep variables from one dataset if I am setting multiple datasets? There is an excel file of the variables that is wanted, it is only variables no data. Then I have my raw data that has the variables but has the data. I want to have a new dataset where I can set my “wanted variables” with my “raw data variables” and just keep those variables, because the raw data will have more variables than wanted.&lt;/P&gt;
&lt;P class="_1qeIAgB0cPwnLhDF9XSiJM"&gt;I know I can do a simple keep statement, I am wanting it to be dynamic, so if the excel file with the desired variable list changes the new dataset will catch it and keep the new added variable. Rather than checking all the variables each time.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 17 Feb 2020 18:45:20 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2020-02-17T18:45:20Z</dc:date>
    <item>
      <title>Keeping variables from datasets</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Keeping-variables-from-datasets/m-p/625294#M20223</link>
      <description>&lt;P class="_1qeIAgB0cPwnLhDF9XSiJM"&gt;Is there a way to keep variables from one dataset if I am setting multiple datasets? There is an excel file of the variables that is wanted, it is only variables no data. Then I have my raw data that has the variables but has the data. I want to have a new dataset where I can set my “wanted variables” with my “raw data variables” and just keep those variables, because the raw data will have more variables than wanted.&lt;/P&gt;&lt;P class="_1qeIAgB0cPwnLhDF9XSiJM"&gt;I know I can do a simple keep statement, I am wanting it to be dynamic, so if the excel file with the desired variable list changes the new dataset will catch it and keep the new added variable. Rather than checking all the variables each time.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Feb 2020 15:01:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Keeping-variables-from-datasets/m-p/625294#M20223</guid>
      <dc:creator>JayceWaylon</dc:creator>
      <dc:date>2020-02-17T15:01:19Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping variables from datasets</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Keeping-variables-from-datasets/m-p/625297#M20224</link>
      <description>&lt;P&gt;HI&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/312519"&gt;@JayceWaylon&lt;/a&gt;&amp;nbsp; An easy and lazy way(&lt;EM&gt;as i am super lazy&lt;/EM&gt;) would be to&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Have your excel as an empty dataset&lt;/P&gt;
&lt;P&gt;&amp;nbsp;2. Use a SET operator with CORR option and append with UNION ALL&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
/*Your raw data*/
data two;
 set sashelp.class;
 retain k 'junk';
run;
/*Your fictitious excel*/
data excel;
 set sashelp.class;
 stop;
run;

proc sql;
create table want as
select *
from excel
union all corr
select *
from two;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is a caveat in the above approach, the position of the variables should match in the select clause&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Feb 2020 15:16:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Keeping-variables-from-datasets/m-p/625297#M20224</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-02-17T15:16:42Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping variables from datasets</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Keeping-variables-from-datasets/m-p/625301#M20225</link>
      <description>&lt;P&gt;Or a proc append is another option provided you are willing to tolerate the WARNING message in the LOG:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
/*Your raw data*/
data two; 
 retain name height;
 set sashelp.class;
 retain k 'junk';
run;
/*Your fictitious excel*/
data excel;
 set sashelp.class;
 stop;
run;

proc append base= excel data=two force;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 17 Feb 2020 15:20:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Keeping-variables-from-datasets/m-p/625301#M20225</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-02-17T15:20:42Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping variables from datasets</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Keeping-variables-from-datasets/m-p/625385#M20242</link>
      <description>&lt;P&gt;1. Import your Excel file, I'm going to assume you know how to do this.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. Create a list of the variables using a macro variable&lt;/P&gt;
&lt;P&gt;3. Use the macro variable&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It really does depend on how the 'empty' variable data set is structured, though. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select varName into :keep_list separated by " "
from importFromExcel;
quit;

data want;
set t1 (keep = &amp;amp;keep_list)
      t2 (keep = ID ....other variables *optional*);

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/312519"&gt;@JayceWaylon&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P class="_1qeIAgB0cPwnLhDF9XSiJM"&gt;Is there a way to keep variables from one dataset if I am setting multiple datasets? There is an excel file of the variables that is wanted, it is only variables no data. Then I have my raw data that has the variables but has the data. I want to have a new dataset where I can set my “wanted variables” with my “raw data variables” and just keep those variables, because the raw data will have more variables than wanted.&lt;/P&gt;
&lt;P class="_1qeIAgB0cPwnLhDF9XSiJM"&gt;I know I can do a simple keep statement, I am wanting it to be dynamic, so if the excel file with the desired variable list changes the new dataset will catch it and keep the new added variable. Rather than checking all the variables each time.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Feb 2020 18:45:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Keeping-variables-from-datasets/m-p/625385#M20242</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-02-17T18:45:20Z</dc:date>
    </item>
  </channel>
</rss>

