<?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: How to perform check condition on the macro variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-perform-check-condition-on-the-macro-variable/m-p/430944#M106541</link>
    <description>Thanks.. this is exactly what I needed..&lt;BR /&gt;</description>
    <pubDate>Thu, 25 Jan 2018 15:16:09 GMT</pubDate>
    <dc:creator>UshaLatha</dc:creator>
    <dc:date>2018-01-25T15:16:09Z</dc:date>
    <item>
      <title>How to perform check condition on the macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-perform-check-condition-on-the-macro-variable/m-p/430777#M106494</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need some help with my code.&lt;/P&gt;&lt;P&gt;I have a dataset with three variables:&lt;/P&gt;&lt;P&gt;data1:&lt;/P&gt;&lt;P&gt;loan_id var1 var2 var2&lt;/P&gt;&lt;P&gt;111&amp;nbsp; 5.6 2.6 3.6&lt;/P&gt;&lt;P&gt;222&amp;nbsp; 2.4 7.8 1.2&lt;/P&gt;&lt;P&gt;333&amp;nbsp; 1.6 8.3 4.4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have to perform sensitivity testing on these variables, check how my model is performing when one of these variable's value changes i.e either increase by 10% or decrease by 10%. I would be using these new dataset for model testing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;eg:&lt;/P&gt;&lt;P&gt;condition1 : when I'm checking for var1 i.e when var1=(var1*0.9) , I want the other variable's values to be same&lt;/P&gt;&lt;P&gt;I want my dataset to be as follows:&lt;/P&gt;&lt;P&gt;loan_id var1 var2 var2&lt;/P&gt;&lt;P&gt;111&amp;nbsp; 5.04 2.6 3.6&lt;/P&gt;&lt;P&gt;222&amp;nbsp; 2.16 7.8 1.2&lt;/P&gt;&lt;P&gt;333&amp;nbsp; 1.44 8.3 4.4&lt;/P&gt;&lt;P&gt;condition2: when I'm checking for var1 i.e when var1=(var1*1.1) , I want the other variable's values to be same&lt;/P&gt;&lt;P&gt;I want my dataset to be as follows:&lt;/P&gt;&lt;P&gt;loan_id var1 var2 var2&lt;/P&gt;&lt;P&gt;111&amp;nbsp;&amp;nbsp;6.16 2.6 3.6&lt;/P&gt;&lt;P&gt;222&amp;nbsp; 2.64 7.8 1.2&lt;/P&gt;&lt;P&gt;333&amp;nbsp; 1.76 8.3 4.4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The issue I am facing is : is there any way to parameterize these conditions.&lt;/P&gt;&lt;P&gt;Suppose if my testname =var1UP10 then var1=(var1*1.1) or if my testname =var1DOWN10 then var1=(var1*0.9)&lt;/P&gt;&lt;P&gt;similarly for other variables. I want to pass the testname as macrovariable and created six different datasets one-by-one.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jan 2018 05:20:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-perform-check-condition-on-the-macro-variable/m-p/430777#M106494</guid>
      <dc:creator>UshaLatha</dc:creator>
      <dc:date>2018-01-25T05:20:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform check condition on the macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-perform-check-condition-on-the-macro-variable/m-p/430782#M106495</link>
      <description>&lt;P&gt;This may work fine or give you the general idea of how it would work.&lt;/P&gt;
&lt;PRE&gt;%marco sensitivityfactoring( varname, UporDown, libin, datasetin, libout, datasetout);


/*comment explaining the macro program parameters above*/


/*marco (variable name, the words UP or DOWN,

path to library/folder where your data are, datasetin is the name of the dataset,

path to library/folder where your new data will go, datasetin is the name of the new dataset,*/


/*Macro program*/


/* define libname*/

libname datain "&amp;amp;libin."; /* path to library/folder where your data are.*/


/*bring data into work directory*/

data haveoriginal;

set datain..&amp;amp;datasetin.; /* the &amp;amp; and period(s) (.) here are important*/ /* datasetin is the name of the dataset */

run;

%if "&amp;amp;UporDown."="UP" %then %let Sensitivityfactor=1.1;

/* we are moving the variable data up 10%*/

%else %if "&amp;amp;UporDown."="DOWN" %then %let Sensitivityfactor=0.9;

/* we are moving the variable data down 10%*/


/* define libname*/

libname dataout "&amp;amp;libout."; /* path to library/folder where your data are.*/


data daatout.&amp;amp;datasetout.;

set haveoriginal;

/* we know what variable we want to change because it's name is in this macro parameter variable name "varname"*/


&amp;amp;varname.=&amp;amp;varname.*&amp;amp;Sensitivityfactor.;

run;


/* we are done now.*/

%mend; /* we close the macro program. We only need to run the above code once to start per session*/


/* now we call our macro program like so.*/


%sensitivityfactoring(var1, UP, C:\path location of file, data1, C:\outputpath, newdatasetname);

%sensitivityfactoring(var1, DOWN, C:\path location of file, data1, C:\outputpath, newdatasetname);

%sensitivityfactoring(var2, UP, C:\path location of file, data1, C:\outputpath, newdatasetname);

%sensitivityfactoring(var2, DOWN, C:\path location of file, data1, C:\outputpath, newdatasetname);

%sensitivityfactoring(var3, UP, C:\path location of file, data1, C:\outputpath, newdatasetname);

%sensitivityfactoring(var3, DOWN, C:\path location of file, data1, C:\outputpath, newdatasetname);


&lt;/PRE&gt;
&lt;P&gt;%marco sensitivityfactoring( varname, UporDown, libin, datasetin, libout, datasetout);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/*comment explaining the macro program parameters above*/&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/*marco (variable name, the words UP or DOWN,&lt;/P&gt;
&lt;P&gt;path to library/folder where your data are, datasetin is the name of the dataset,&lt;/P&gt;
&lt;P&gt;path to library/folder where your new data will go, datasetin is the name of the new dataset,*/&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/*Macro program*/&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/* define libname*/&lt;/P&gt;
&lt;P&gt;libname datain "&amp;amp;libin."; /* path to library/folder where your data are.*/&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/*bring data into work directory*/&lt;/P&gt;
&lt;P&gt;data haveoriginal;&lt;/P&gt;
&lt;P&gt;set datain..&amp;amp;datasetin.; /* the &amp;amp; and period(s) (.) here are important*/ /* datasetin is the name of the dataset */&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;%if "&amp;amp;UporDown."="UP" %then %let Sensitivityfactor=1.1;&lt;/P&gt;
&lt;P&gt;/* we are moving the variable data up 10%*/&lt;/P&gt;
&lt;P&gt;%else %if "&amp;amp;UporDown."="DOWN" %then %let Sensitivityfactor=0.9;&lt;/P&gt;
&lt;P&gt;/* we are moving the variable data down 10%*/&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/* define libname*/&lt;/P&gt;
&lt;P&gt;libname dataout "&amp;amp;libout."; /* path to library/folder where your data are.*/&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data daatout.&amp;amp;datasetout.;&lt;/P&gt;
&lt;P&gt;set haveoriginal;&lt;/P&gt;
&lt;P&gt;/* we know what variable we want to change because it's name is in this macro parameter variable name "varname"*/&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;amp;varname.=&amp;amp;varname.*&amp;amp;Sensitivityfactor.;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/* we are done now.*/&lt;/P&gt;
&lt;P&gt;%mend; /* we close the macro program. We only need to run the above code once to start per session*/&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/* now we call our macro program like so.*/&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%sensitivityfactoring(var1, UP, C:\path location of file, data1, C:\outputpath, newdatasetname);&lt;/P&gt;
&lt;P&gt;%sensitivityfactoring(var1, DOWN, C:\path location of file, data1, C:\outputpath, newdatasetname);&lt;/P&gt;
&lt;P&gt;%sensitivityfactoring(var2, UP, C:\path location of file, data1, C:\outputpath, newdatasetname);&lt;/P&gt;
&lt;P&gt;%sensitivityfactoring(var2, DOWN, C:\path location of file, data1, C:\outputpath, newdatasetname);&lt;/P&gt;
&lt;P&gt;%sensitivityfactoring(var3, UP, C:\path location of file, data1, C:\outputpath, newdatasetname);&lt;/P&gt;
&lt;P&gt;%sensitivityfactoring(var3, DOWN, C:\path location of file, data1, C:\outputpath, newdatasetname);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jan 2018 05:55:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-perform-check-condition-on-the-macro-variable/m-p/430782#M106495</guid>
      <dc:creator>ptimusk</dc:creator>
      <dc:date>2018-01-25T05:55:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform check condition on the macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-perform-check-condition-on-the-macro-variable/m-p/430803#M106500</link>
      <description>&lt;P&gt;You might be making this much more difficult than it needs to be.&amp;nbsp; For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;array drivers {6} var1-var6;&lt;/P&gt;
&lt;P&gt;do dr = 1 to 6;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;driver = vname(drivers{dr});&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;original_value = drivers{dr};&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;do factor = 0.9, 1.1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; driver{dr} = factor * driver{dr};&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; output;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; driver{dr} = original_value;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;end;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instead of creating new variables, create more observations (using the same variable names).&amp;nbsp; Each observation contains one set of values to test, and includes the variable DRIVER (name of the driver being tested) and FACTOR (0.9 or 1.1).&amp;nbsp; ORIGINAL_VALUE is optional and you may decide to drop it.&amp;nbsp; But it might be convenient to keep it around.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just imagine ... you can use the same modeling equation every time because the variable names don't change.&amp;nbsp; You just have to subset (or possibly use a BY statement) based on DRIVER and FACTOR.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jan 2018 08:14:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-perform-check-condition-on-the-macro-variable/m-p/430803#M106500</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-01-25T08:14:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform check condition on the macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-perform-check-condition-on-the-macro-variable/m-p/430944#M106541</link>
      <description>Thanks.. this is exactly what I needed..&lt;BR /&gt;</description>
      <pubDate>Thu, 25 Jan 2018 15:16:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-perform-check-condition-on-the-macro-variable/m-p/430944#M106541</guid>
      <dc:creator>UshaLatha</dc:creator>
      <dc:date>2018-01-25T15:16:09Z</dc:date>
    </item>
  </channel>
</rss>

