<?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: Issues with VARNAME when bringing in data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Issues-with-VARNAME-when-bringing-in-data/m-p/383811#M91576</link>
    <description>&lt;P&gt;If your data set were to contain these variables, would you want to keep them?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;CUPID&lt;/P&gt;
&lt;P&gt;STUPID&lt;/P&gt;
&lt;P&gt;PIDDLE&lt;/P&gt;
&lt;P&gt;RAPID&lt;/P&gt;</description>
    <pubDate>Fri, 28 Jul 2017 17:08:46 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2017-07-28T17:08:46Z</dc:date>
    <item>
      <title>Issues with VARNAME when bringing in data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issues-with-VARNAME-when-bringing-in-data/m-p/383712#M91549</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've created a very basic macro to bring in several datasets. &amp;nbsp;I only want to keep variables in the datasets that contain the word&amp;nbsp;"PID" (it's typically the last 3 characters in the variable name but that's not always the case). &amp;nbsp;I created the following macro, but I get an error saying that "variable VARNAME is not on file". &amp;nbsp; Any help would be greatly appreciated, thanks!&lt;/P&gt;&lt;PRE&gt;%macro datain (old,new);
data &amp;amp;new;
set dataset.&amp;amp;old;
where VARNAME contains 'PID';
run;
%mend;&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 Jul 2017 14:27:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issues-with-VARNAME-when-bringing-in-data/m-p/383712#M91549</guid>
      <dc:creator>glcoolj12</dc:creator>
      <dc:date>2017-07-28T14:27:45Z</dc:date>
    </item>
    <item>
      <title>Re: Issues with VARNAME when bringing in data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issues-with-VARNAME-when-bringing-in-data/m-p/383724#M91553</link>
      <description>&lt;P&gt;There is no such variable called varname in your dataset, where did you get the idea there was? &amp;nbsp;How are you getting the data, as if you used a good methodology - text file and write datastep - then you would just omit these from the datastep import process.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  select distinct NAME
  into   :L separated by " "
  from   SASHELP.VCOLUMN
  where  LIBNAME="WORK" 
     and MEMNAME="HAVE"
     and index(NAME,"PID") &amp;gt; 0;
quit;

data want;
  set have (drop=&amp;amp;L.);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 Jul 2017 14:45:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issues-with-VARNAME-when-bringing-in-data/m-p/383724#M91553</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-07-28T14:45:36Z</dc:date>
    </item>
    <item>
      <title>Re: Issues with VARNAME when bringing in data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issues-with-VARNAME-when-bringing-in-data/m-p/383729#M91554</link>
      <description>&lt;P&gt;Slight change from the code suggested by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;&amp;nbsp;as that dropped rather than kept the variable(s) of interest, and the following keeps it as a macro:&lt;/P&gt;
&lt;PRE&gt;%macro datain (old,new);
  proc sql noprint;
    select name into :keeps separated by ' '
      from dictionary.columns
        where libname eq 'DATASET' and
              memname eq upcase("&amp;amp;old.") and
              upcase(name) contains 'EX'
    ;
  quit;
  
  data &amp;amp;new;
    set dataset.&amp;amp;old (keep=&amp;amp;keeps.);
  run;
%mend datain;

libname dataset '/folders/myfolders';
data dataset.test;
  set sashelp.class;
run;

%datain(test,newtest)
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jul 2017 14:52:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issues-with-VARNAME-when-bringing-in-data/m-p/383729#M91554</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-07-28T14:52:23Z</dc:date>
    </item>
    <item>
      <title>Re: Issues with VARNAME when bringing in data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issues-with-VARNAME-when-bringing-in-data/m-p/383811#M91576</link>
      <description>&lt;P&gt;If your data set were to contain these variables, would you want to keep them?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;CUPID&lt;/P&gt;
&lt;P&gt;STUPID&lt;/P&gt;
&lt;P&gt;PIDDLE&lt;/P&gt;
&lt;P&gt;RAPID&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jul 2017 17:08:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issues-with-VARNAME-when-bringing-in-data/m-p/383811#M91576</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-07-28T17:08:46Z</dc:date>
    </item>
    <item>
      <title>Re: Issues with VARNAME when bringing in data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issues-with-VARNAME-when-bringing-in-data/m-p/383834#M91582</link>
      <description>&lt;P&gt;Yes. &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;'dataset' is the libname I assigned to the folder that holds all 50+ datasets (.sas7bdat)&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jul 2017 17:31:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issues-with-VARNAME-when-bringing-in-data/m-p/383834#M91582</guid>
      <dc:creator>glcoolj12</dc:creator>
      <dc:date>2017-07-28T17:31:43Z</dc:date>
    </item>
    <item>
      <title>Re: Issues with VARNAME when bringing in data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issues-with-VARNAME-when-bringing-in-data/m-p/383857#M91591</link>
      <description>&lt;P&gt;Thank you all for your help. &amp;nbsp;I was able to piece together a program that works. &amp;nbsp;Thanks!!&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%macro k;&lt;BR /&gt;%put &amp;amp;keep_vars.;&lt;BR /&gt;%mend k;&lt;BR /&gt;&lt;BR /&gt;%macro datain (old, new);
data &amp;amp;new;
set dataset.&amp;amp;old;
run;

proc sql noprint;
select trim(compress(name))
into :keep_vars separated by ' '
from sashelp.vcolumn
where libname = upcase('work')
and memname = upcase('&amp;amp;new.')
and upcase(name) like '%PID%';
quit;

%k;

data &amp;amp;new;
set &amp;amp;new;
keep &amp;amp;keep_vars.;
run;
%mend;  &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jul 2017 19:20:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issues-with-VARNAME-when-bringing-in-data/m-p/383857#M91591</guid>
      <dc:creator>glcoolj12</dc:creator>
      <dc:date>2017-07-28T19:20:45Z</dc:date>
    </item>
  </channel>
</rss>

