<?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: Check if Multiple Variables exist in a SAS Dataset in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Check-if-Multiple-Variables-exist-in-a-SAS-Dataset/m-p/186439#M3830</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks all for your help. Xia Keshan's code was truly helpful.&amp;nbsp; I will put this as Answered.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Happy Holidays!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 03 Dec 2014 15:57:42 GMT</pubDate>
    <dc:creator>jprosenbaum8908</dc:creator>
    <dc:date>2014-12-03T15:57:42Z</dc:date>
    <item>
      <title>Check if Multiple Variables exist in a SAS Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Check-if-Multiple-Variables-exist-in-a-SAS-Dataset/m-p/186429#M3820</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a dataset that I want to perform checks on:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1st Check: determine if all wanted variables exist in the dataset&lt;/P&gt;&lt;P&gt;2nd Check: determine if there are any extra/unwanted variables in the dataset other than the wanted variables&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Let's say I am using this data below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data test1;&lt;/P&gt;&lt;P&gt;input id score1 score2 score3 score4 score5 score6;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;24 100 97 99 100 85 85&lt;/P&gt;&lt;P&gt;28 98 87 98 100 44 90&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to check if id, score1 score2 score3 and score4 exist in the dataset (let's assume I am pulling this dataset from a database and checking to see if someone created the correct dataset with those wanted variables only).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My desire is to perform those two checks above and either output a dataset called check_var_problem1, if not all the wanted variables exist, and check_var_problem2, if there exists more than the wanted variables in the dataset. If a dataset cannot be created with the problems, then a note would be acceptable in the LOG that says something like (Check1): "score2 is not in this dataset" or (Check2): "This dataset contains score5, score6 in the dataset".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tried using a loop to check for the missing variables, as well as creating macro variables.&amp;nbsp; See my code below:&lt;/P&gt;&lt;P&gt;%let var1 = id;&lt;/P&gt;&lt;P&gt;%let var2 = score1;&lt;/P&gt;&lt;P&gt;%let var3 = score2;&lt;/P&gt;&lt;P&gt;%let var4 = score3;&lt;/P&gt;&lt;P&gt;%let var5 = score4;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data check_var_problem1;&lt;/P&gt;&lt;P&gt;dsid = open('test1');&lt;/P&gt;&lt;P&gt;do i = 1 to 5;&lt;/P&gt;&lt;P&gt;check=varnum(dsid, 'var&amp;amp;i');&lt;/P&gt;&lt;P&gt;if check = 0 then put 'var&amp;amp;1 does not exist';&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any help is appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Nov 2014 18:45:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Check-if-Multiple-Variables-exist-in-a-SAS-Dataset/m-p/186429#M3820</guid>
      <dc:creator>jprosenbaum8908</dc:creator>
      <dc:date>2014-11-25T18:45:36Z</dc:date>
    </item>
    <item>
      <title>Re: Check if Multiple Variables exist in a SAS Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Check-if-Multiple-Variables-exist-in-a-SAS-Dataset/m-p/186430#M3821</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Perhaps consider checking the metadata on the dataset instead.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Look into SASHELP.VCOLUMN or dictionary.column table that SAS has. &lt;/P&gt;&lt;P&gt;Then if you have your data structure defined in a dataset you can do a SQL join or Datastep Merge and easily identify which variables are present/absent.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Nov 2014 18:53:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Check-if-Multiple-Variables-exist-in-a-SAS-Dataset/m-p/186430#M3821</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2014-11-25T18:53:21Z</dc:date>
    </item>
    <item>
      <title>Re: Check if Multiple Variables exist in a SAS Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Check-if-Multiple-Variables-exist-in-a-SAS-Dataset/m-p/186431#M3822</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I need something to be displayed in the log for a quick verification. Thanks, but I don't think that is what I am looking for as an answer. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Nov 2014 19:36:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Check-if-Multiple-Variables-exist-in-a-SAS-Dataset/m-p/186431#M3822</guid>
      <dc:creator>jprosenbaum8908</dc:creator>
      <dc:date>2014-11-25T19:36:46Z</dc:date>
    </item>
    <item>
      <title>Re: Check if Multiple Variables exist in a SAS Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Check-if-Multiple-Variables-exist-in-a-SAS-Dataset/m-p/186432#M3823</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;A few items to note ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;First, single quotes suppresses all macro-related activity.&amp;nbsp; All single quotes must become double quotes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Second, var&amp;amp;i is looking for a macro variable named &amp;amp;i.&amp;nbsp; You don't have one, nor do you need one.&amp;nbsp; Instead of %LET statements, you could include these statements in a DATA step:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;var1 = 'id';&lt;/P&gt;&lt;P&gt;var2 = 'score1';&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;var5 = 'score4';&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then use DATA step processing:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;array vars {5} var1-var5;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Inside the loop:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;check = varnum(dsid, vars{i});&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'd suggest you get the code working 100% for a single data set without any macro language involved.&amp;nbsp; Then consider how to use macro language in the solution.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Nov 2014 19:46:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Check-if-Multiple-Variables-exist-in-a-SAS-Dataset/m-p/186432#M3823</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2014-11-25T19:46:25Z</dc:date>
    </item>
    <item>
      <title>Re: Check if Multiple Variables exist in a SAS Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Check-if-Multiple-Variables-exist-in-a-SAS-Dataset/m-p/186433#M3824</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This is a long way. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm sure you could do it simpler with some call vnext functions and such in a single data step but I don't know how that would work. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;SPAN style="color: #011993;"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/SPAN&gt; class;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;SPAN style="color: #0433ff;"&gt;set&lt;/SPAN&gt; sashelp.class;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;SPAN style="color: #0433ff;"&gt;drop&lt;/SPAN&gt; sex age;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;weight2=weight*&lt;SPAN style="color: #009193;"&gt;&lt;STRONG&gt;2&lt;/STRONG&gt;&lt;/SPAN&gt;;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New'; color: #011993;"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;SPAN style="color: #000000;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;SPAN style="color: #011993;"&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt;&lt;/SPAN&gt; compare_data(base=, compare=);&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;proc sql noprint;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&amp;nbsp; create table base_in as&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&amp;nbsp; select name &lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&amp;nbsp; from sashelp.vcolumn&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&amp;nbsp; where libname=upper(scan(&lt;SPAN style="color: #942193;"&gt;"&amp;amp;base"&lt;/SPAN&gt;, &lt;SPAN style="color: #009193;"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/SPAN&gt;, &lt;SPAN style="color: #942193;"&gt;"."&lt;/SPAN&gt;))&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&amp;nbsp; and memname=upper(scan(&lt;SPAN style="color: #942193;"&gt;"&amp;amp;base"&lt;/SPAN&gt;, &lt;SPAN style="color: #009193;"&gt;&lt;STRONG&gt;2&lt;/STRONG&gt;&lt;/SPAN&gt;, &lt;SPAN style="color: #942193;"&gt;"."&lt;/SPAN&gt;))&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&amp;nbsp; order by varnum;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;quit;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;proc sql noprint;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&amp;nbsp; create table compare_in as&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&amp;nbsp; select name &lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&amp;nbsp; from sashelp.vcolumn&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&amp;nbsp; where libname=upper(scan(&lt;SPAN style="color: #942193;"&gt;"&amp;amp;compare"&lt;/SPAN&gt;, &lt;SPAN style="color: #009193;"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/SPAN&gt;, &lt;SPAN style="color: #942193;"&gt;"."&lt;/SPAN&gt;))&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&amp;nbsp; and memname=upper(scan(&lt;SPAN style="color: #942193;"&gt;"&amp;amp;compare"&lt;/SPAN&gt;, &lt;SPAN style="color: #009193;"&gt;&lt;STRONG&gt;2&lt;/STRONG&gt;&lt;/SPAN&gt;, &lt;SPAN style="color: #942193;"&gt;"."&lt;/SPAN&gt;))&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&amp;nbsp; order by varnum;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;quit;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;proc sql;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&amp;nbsp; create table comparison as&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&amp;nbsp; select a.name as base_var, b.name as compare_var,&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&amp;nbsp; case when missing(a.name) then catx(&lt;SPAN style="color: #942193;"&gt;"-"&lt;/SPAN&gt;, &lt;SPAN style="color: #942193;"&gt;"Comparison dataset has extra variable"&lt;/SPAN&gt;, b.name)&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&amp;nbsp; when missing(b.name) then catx(&lt;SPAN style="color: #942193;"&gt;"-"&lt;/SPAN&gt;, &lt;SPAN style="color: #942193;"&gt;"Comparison dataset is missing variable"&lt;/SPAN&gt;, a.name)&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New'; color: #942193;"&gt;&lt;SPAN style="color: #000000;"&gt;&amp;nbsp; when a.name=b.name then &lt;/SPAN&gt;"Variable in both datasets"&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New'; color: #942193;"&gt;&lt;SPAN style="color: #000000;"&gt;&amp;nbsp; else &lt;/SPAN&gt;"CHECKME"&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&amp;nbsp; end as comparison&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&amp;nbsp; from base_in as a&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&amp;nbsp; full join compare_in as b&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&amp;nbsp; on a.name=b.name;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;quit;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;data _null_;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;set comparison;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New'; color: #942193;"&gt;&lt;SPAN style="color: #000000;"&gt;if comparison not eq &lt;/SPAN&gt;"Variable in both datasets"&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&amp;nbsp; then put &lt;SPAN style="color: #942193;"&gt;"ERROR:"&lt;/SPAN&gt; comparison;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;run;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New'; color: #011993;"&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt;&lt;SPAN style="color: #000000;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;%&lt;STRONG&gt;&lt;EM&gt;compare_data&lt;/EM&gt;&lt;/STRONG&gt;(base=sashelp.class, compare=work.class);&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Nov 2014 19:59:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Check-if-Multiple-Variables-exist-in-a-SAS-Dataset/m-p/186433#M3824</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2014-11-25T19:59:18Z</dc:date>
    </item>
    <item>
      <title>Re: Check if Multiple Variables exist in a SAS Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Check-if-Multiple-Variables-exist-in-a-SAS-Dataset/m-p/186434#M3825</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The method I always use is based on proc contents. It's almost similar to the method Reeza is describing, but less coding.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You run a proc contents on the test1 data-set. The keep variables you can use not only to check the varname but also if type, length or order matches.&lt;/P&gt;&lt;P&gt;proc contents data=test1 out=meta_test1 (keep=name type length varnum);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then you create a template file (or use the one that's registered in the metadata);&lt;/P&gt;&lt;P&gt;data meta_temp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; attrib&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Id&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; length=8&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; format=8.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; score1 length=8 format=8.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; etc...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; stop;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then the rest is the same as the proc sql; create table comparison from Reeza's code.&lt;/P&gt;&lt;P&gt;If you want to check of order, type, length, just add them to the join.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Nov 2014 12:18:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Check-if-Multiple-Variables-exist-in-a-SAS-Dataset/m-p/186434#M3825</guid>
      <dc:creator>sdoorneveld</dc:creator>
      <dc:date>2014-11-28T12:18:47Z</dc:date>
    </item>
    <item>
      <title>Re: Check if Multiple Variables exist in a SAS Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Check-if-Multiple-Variables-exist-in-a-SAS-Dataset/m-p/186435#M3826</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let var1 = Age;&lt;BR /&gt;%let var2 = Sex;&lt;BR /&gt;%let var3 = blabla;&lt;/P&gt;&lt;P&gt;/*determines variable of database*/&lt;BR /&gt;proc sql;&lt;BR /&gt;create table varb as select name from sashelp.vcolumn&lt;BR /&gt;where memname='CLASS';&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;/*write the variables to search for in a database*/&lt;BR /&gt;%macro a;&lt;/P&gt;&lt;P&gt;%let k=1;&lt;/P&gt;&lt;P&gt;data tosearch;&lt;BR /&gt;length vartosearch $ 20;&lt;BR /&gt;%do %while (%symexist(var&amp;amp;k));&lt;BR /&gt;vartosearch="&amp;amp;&amp;amp;var&amp;amp;k";&lt;BR /&gt;output;&lt;BR /&gt;%let k=%eval(&amp;amp;k+1);&lt;BR /&gt;%end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%mend a;&lt;/P&gt;&lt;P&gt;%a&lt;/P&gt;&lt;P&gt;/*determines the 2 wanted databases*/&lt;BR /&gt;proc sql;&lt;BR /&gt;create table check_var_problem2 as&lt;BR /&gt;select name from varb&lt;BR /&gt;except &lt;BR /&gt;select vartosearch from tosearch;&lt;BR /&gt;create table check_var_problem1 as&lt;BR /&gt;select vartosearch from tosearch&lt;BR /&gt;except &lt;BR /&gt;select name from varb;&lt;BR /&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Nov 2014 14:02:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Check-if-Multiple-Variables-exist-in-a-SAS-Dataset/m-p/186435#M3826</guid>
      <dc:creator>Loko</dc:creator>
      <dc:date>2014-11-28T14:02:43Z</dc:date>
    </item>
    <item>
      <title>Re: Check if Multiple Variables exist in a SAS Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Check-if-Multiple-Variables-exist-in-a-SAS-Dataset/m-p/186436#M3827</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think that something like the following would accomplish what you want:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input id score1 x score3 y score5 score6;&lt;/P&gt;&lt;P&gt;&amp;nbsp; cards;&lt;/P&gt;&lt;P&gt;24 100 97 99 100 85 85&lt;/P&gt;&lt;P&gt;28 98 87 98 100 44 90&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro check(filenm,vars);&lt;/P&gt;&lt;P&gt;&amp;nbsp; data check (drop=&amp;amp;vars.);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set &amp;amp;filenm. (obs=1);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; _error_=0;&lt;/P&gt;&lt;P&gt;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; proc sql noprint;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select name&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; into :vnames separated by " "&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from dictionary.columns&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where libname="WORK" and&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; memname="CHECK"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %let nvar=&amp;amp;sqlobs.;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %if nvar=0 %then %put "There were no extra variables";&lt;/P&gt;&lt;P&gt;&amp;nbsp; %else %then %put "Unexpected vars in file: &amp;amp;vnames.";&lt;/P&gt;&lt;P&gt;%mend check;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%check(test1,id score1 score2 score3 score4)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Nov 2014 14:52:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Check-if-Multiple-Variables-exist-in-a-SAS-Dataset/m-p/186436#M3827</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2014-11-28T14:52:05Z</dc:date>
    </item>
    <item>
      <title>Re: Check if Multiple Variables exist in a SAS Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Check-if-Multiple-Variables-exist-in-a-SAS-Dataset/m-p/186437#M3828</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Why not use Proc Compare?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc compare data=Dataset1 compare=Dataset2 nosummary listvar;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Nov 2014 14:59:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Check-if-Multiple-Variables-exist-in-a-SAS-Dataset/m-p/186437#M3828</guid>
      <dc:creator>Fraktalnisse</dc:creator>
      <dc:date>2014-11-28T14:59:45Z</dc:date>
    </item>
    <item>
      <title>Re: Check if Multiple Variables exist in a SAS Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Check-if-Multiple-Variables-exist-in-a-SAS-Dataset/m-p/186438#M3829</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE&gt;
Data test1;
input id score1 score2 score3 score4 score5 score6;
cards;
24 100 97 99 100 85 85
28 98 87 98 100 44 90
run;

%macro check(libname= ,tname= ,vars= );
data have;
 list="&amp;amp;vars";
 do i=1 to countw(list);
&amp;nbsp; var=scan(list,i);output;
 end;
 keep var;
run;

proc sql noprint;
create table a as
 select upcase(var) as var from have
 except
 select upcase(name) from dictionary.columns where libname="%upcase(&amp;amp;libname)" and memname="%upcase(&amp;amp;tname)";

create table b as
 select upcase(name) as var from dictionary.columns where libname="%upcase(&amp;amp;libname)" and memname="%upcase(&amp;amp;tname)"
 except
 select upcase(var) from have ;

select count(*) into : a from a;
select count(*) into : b from b;

select var into : alist separated by ' ' from a;
select var into : blist separated by ' ' from b;

quit;

%if &amp;amp;a eq 0 %then %put WARNING: All the variable is included. ;
 %else &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;%put WARNING: &amp;amp;alist variables are not included. ;

%if &amp;amp;b eq 0 %then %put WARNING: there are not extra variables. ;
 %else &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;%put WARNING: &amp;amp;blist variables are extra variables. ;
%mend check;

%check(libname=work ,tname=test1 ,vars= id score1 score2 score3 score4)



&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Nov 2014 16:31:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Check-if-Multiple-Variables-exist-in-a-SAS-Dataset/m-p/186438#M3829</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2014-11-28T16:31:38Z</dc:date>
    </item>
    <item>
      <title>Re: Check if Multiple Variables exist in a SAS Dataset</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Check-if-Multiple-Variables-exist-in-a-SAS-Dataset/m-p/186439#M3830</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks all for your help. Xia Keshan's code was truly helpful.&amp;nbsp; I will put this as Answered.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Happy Holidays!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Dec 2014 15:57:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Check-if-Multiple-Variables-exist-in-a-SAS-Dataset/m-p/186439#M3830</guid>
      <dc:creator>jprosenbaum8908</dc:creator>
      <dc:date>2014-12-03T15:57:42Z</dc:date>
    </item>
  </channel>
</rss>

