<?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: Macro to stack datasets but different years means different procedures in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-to-stack-datasets-but-different-years-means-different/m-p/367674#M24064</link>
    <description>&lt;P&gt;Kurt,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you mean something like this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro nonadmin(year) / mindelimiter=',';
%if &amp;amp;year in 2011,2012,2013 %then %do;

data survey_&amp;amp;year(rename=(sex=sex1));
set mywork.combined_sample_&amp;amp;year_7;
run;

data admin_&amp;amp;year(keep=gender calc person_id sex agen);
set mywork.combined_sample_&amp;amp;year._7;
run;

proc sort data= survey_&amp;amp;year; by person_id;
proc sort data= admin_&amp;amp;year; by person_id;

data combine_&amp;amp;year;
set ssurvey_&amp;amp;year admin_&amp;amp;year;
by person_id;
if first.person_id and last.person_id then output
run;

%end;
 %else %if &amp;amp;year in 2014,2015 %then %do;

data survey_&amp;amp;year(rename=(sex=sex1));
set finaldat.survey&amp;amp;year;
run;

data admin_&amp;amp;year(keep=gender calc person_id sex agen);
set mywork.combined_sample_&amp;amp;year._7;
run;

proc sort data= survey_&amp;amp;year; by person_id;
proc sort data= admin_&amp;amp;year; by person_id;

data combine_&amp;amp;year;
set survey_&amp;amp;year admin_&amp;amp;year;
by person_id;
if first.person_id and last.person_id then output ;


run;
%end;

%mend nonadmin;

%nonadmin (2011);
%nonadmin (2012);
%nonadmin (2013);
%nonadmin (2014);
%nonadmin (2015);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;When I run this I get the following error,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: 
       &amp;amp;year in 2011,2012,2013 
ERROR: The macro NONADMIN will stop executing.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Utilising Macro's are all fairly new to me but I appreciate any input.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 16 Jun 2017 11:21:31 GMT</pubDate>
    <dc:creator>Sean_OConnor</dc:creator>
    <dc:date>2017-06-16T11:21:31Z</dc:date>
    <item>
      <title>Macro to stack datasets but different years means different procedures</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-to-stack-datasets-but-different-years-means-different/m-p/367670#M24062</link>
      <description>&lt;P&gt;Folks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm having a bit of trouble trying to understand why my code won't work. I've created a macro in order to carry out two different processes depending on the time period.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically what I have is a datasource based of survey response and one based off administrative data.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, not all the individuals who are in the survey are actually in the administrative data set.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Therefore what I would like to do is stack on my missing individuals to my dataset to have a hybrid of survey values(when we can't find the person on the admin dataset) and admin values(when the person is on the admin dataset).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Depending on the year there is a need to call on different datasets. Therefore, I've created this macro.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I'm having issue getting it to run. Any input would be great. Perhaps I'm missing %end statment somwhere or something?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be great.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro nonadmin;

%if year = 2011 %to 2013 %then %do;

data survey_&amp;amp;year(rename=(sex=sex1));
set mywork.combined_sample_&amp;amp;year_7;
run;

data admin_&amp;amp;year(keep=gender calc person_id sex agen);
set mywork.combined_sample_&amp;amp;year._7;
run;

proc sort data= survey_&amp;amp;year; by person_id;
proc sort data= admin_&amp;amp;year; by person_id;

data combine_&amp;amp;year;
set ssurvey_&amp;amp;year admin_&amp;amp;year;
by person_id;
if first.person_id and last.person_id then output
run;

%end;
 %else %if year = 2014 %to 2015 %then %do;

data survey_&amp;amp;year(rename=(sex=sex1));
set finaldat.survey&amp;amp;year;
run;

data admin_&amp;amp;year(keep=gender calc person_id sex agen);
set mywork.combined_sample_&amp;amp;year._7;
run;

proc sort data= survey_&amp;amp;year; by person_id;
proc sort data= admin_&amp;amp;year; by person_id;

data combine_&amp;amp;year;
set survey_&amp;amp;year admin_&amp;amp;year;
by person_id;
if first.person_id and last.person_id then output ;


run;
%end;

%mend nonadmin;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 16 Jun 2017 11:09:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-to-stack-datasets-but-different-years-means-different/m-p/367670#M24062</guid>
      <dc:creator>Sean_OConnor</dc:creator>
      <dc:date>2017-06-16T11:09:15Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to stack datasets but different years means different procedures</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-to-stack-datasets-but-different-years-means-different/m-p/367673#M24063</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if year = 2011 %to 2013 %then %do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The text(!) "year" can never be equal to the text "2011".&lt;/P&gt;
&lt;P&gt;That the %to in a condition does not throw an error baffles me, I must say. AFAIK, %to is only usable in a iterative %do statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You probably wanted something along the line&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options minoperator;

%macro nonadmin(year) / mindelimiter=',';
%if &amp;amp;year in 2011,2012,2013 %then %do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Also see &lt;A href="http://support.sas.com/kb/35/591.html" target="_blank"&gt;http://support.sas.com/kb/35/591.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jun 2017 11:12:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-to-stack-datasets-but-different-years-means-different/m-p/367673#M24063</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-06-16T11:12:39Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to stack datasets but different years means different procedures</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-to-stack-datasets-but-different-years-means-different/m-p/367674#M24064</link>
      <description>&lt;P&gt;Kurt,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you mean something like this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro nonadmin(year) / mindelimiter=',';
%if &amp;amp;year in 2011,2012,2013 %then %do;

data survey_&amp;amp;year(rename=(sex=sex1));
set mywork.combined_sample_&amp;amp;year_7;
run;

data admin_&amp;amp;year(keep=gender calc person_id sex agen);
set mywork.combined_sample_&amp;amp;year._7;
run;

proc sort data= survey_&amp;amp;year; by person_id;
proc sort data= admin_&amp;amp;year; by person_id;

data combine_&amp;amp;year;
set ssurvey_&amp;amp;year admin_&amp;amp;year;
by person_id;
if first.person_id and last.person_id then output
run;

%end;
 %else %if &amp;amp;year in 2014,2015 %then %do;

data survey_&amp;amp;year(rename=(sex=sex1));
set finaldat.survey&amp;amp;year;
run;

data admin_&amp;amp;year(keep=gender calc person_id sex agen);
set mywork.combined_sample_&amp;amp;year._7;
run;

proc sort data= survey_&amp;amp;year; by person_id;
proc sort data= admin_&amp;amp;year; by person_id;

data combine_&amp;amp;year;
set survey_&amp;amp;year admin_&amp;amp;year;
by person_id;
if first.person_id and last.person_id then output ;


run;
%end;

%mend nonadmin;

%nonadmin (2011);
%nonadmin (2012);
%nonadmin (2013);
%nonadmin (2014);
%nonadmin (2015);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;When I run this I get the following error,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: 
       &amp;amp;year in 2011,2012,2013 
ERROR: The macro NONADMIN will stop executing.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Utilising Macro's are all fairly new to me but I appreciate any input.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jun 2017 11:21:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-to-stack-datasets-but-different-years-means-different/m-p/367674#M24064</guid>
      <dc:creator>Sean_OConnor</dc:creator>
      <dc:date>2017-06-16T11:21:31Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to stack datasets but different years means different procedures</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-to-stack-datasets-but-different-years-means-different/m-p/367676#M24065</link>
      <description>&lt;P&gt;You missed to set the option I gave you:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*options minoperator;
%macro nonadmin(year) / mindelimiter=',';
%if &amp;amp;year in 2011,2012,2013 %then %do;
%put the value was found;
%end;
%mend;
%nonadmin(2011)
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;results in&lt;/P&gt;
&lt;PRE&gt;24         *options minoperator;
25         %macro nonadmin(year) / mindelimiter=',';
26         %if &amp;amp;year in 2011,2012,2013 %then %do;
27         %put the value was found;
28         %end;
29         %mend;
30         %nonadmin(2011)
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: 
       &amp;amp;year in 2011,2012,2013 
ERROR: The macro NONADMIN will stop executing.
&lt;/PRE&gt;
&lt;P&gt;but&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options minoperator;
%macro nonadmin(year) / mindelimiter=',';
%if &amp;amp;year in 2011,2012,2013 %then %do;
%put the value was found;
%end;
%mend;
%nonadmin(2011)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;results in&lt;/P&gt;
&lt;PRE&gt;24         options minoperator;
25         %macro nonadmin(year) / mindelimiter=',';
26         %if &amp;amp;year in 2011,2012,2013 %then %do;
27         %put the value was found;
28         %end;
29         %mend;
30         %nonadmin(2011)
the value was found
&lt;/PRE&gt;</description>
      <pubDate>Fri, 16 Jun 2017 11:28:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-to-stack-datasets-but-different-years-means-different/m-p/367676#M24065</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-06-16T11:28:29Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to stack datasets but different years means different procedures</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-to-stack-datasets-but-different-years-means-different/m-p/367680#M24066</link>
      <description>&lt;P&gt;Would it not be simpler to put the data together, then do the processing?&lt;/P&gt;
&lt;PRE&gt;data total_survey;
  set survey: indsname=tmp;
  year=scan(tmp,2,"_");
run;

data total_admin;
  set admin: indsname=tmp;
  year=scan(tmp,2,"_");
run;&lt;/PRE&gt;
&lt;P&gt;Its just a matter of changing the set statements to be for your data. &amp;nbsp;The you have a total of each datasets to work with, avoids all the looping.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jun 2017 11:40:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macro-to-stack-datasets-but-different-years-means-different/m-p/367680#M24066</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-06-16T11:40:56Z</dc:date>
    </item>
  </channel>
</rss>

