<?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: Using Macro to create new variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-Macro-to-create-new-variables/m-p/176984#M33874</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;With a text file you can specify a custom format on reading the data.&lt;/P&gt;&lt;P&gt;I am guessing that you want 1 for Yes and 0 for No in your final form.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Proc format;&lt;/P&gt;&lt;P&gt;invalue MyYesNo&lt;/P&gt;&lt;P&gt;'1-Yes' = 1&lt;/P&gt;&lt;P&gt;'0-No' = 0&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; infile "your file name to read" &amp;lt;options to read&amp;gt;; /* if you used proc import you can look at the resulting code in the log to get this */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; informat&amp;nbsp; m2blue q1green&amp;nbsp; k5orange&amp;nbsp; MyYesNo. ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; input StudyID $1-2 CaseID $4-6 m2blue 8-12 q1green 14-18 k5orange 20-24; /* what ever the input statement needs*/&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 08 Oct 2014 19:48:05 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2014-10-08T19:48:05Z</dc:date>
    <item>
      <title>Using Macro to create new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Macro-to-create-new-variables/m-p/176980#M33870</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi SAS users,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm working on a macro where I'd like to 1) re-code values and 2)convert those values from character to numeric. As I have over 20 variables that require re-coding and convert, I'm hoping to use a macro to make it as efficient as possible.&amp;nbsp; Thus far, I've only been able to figure out how to do one variable at a time within the data step.&amp;nbsp; Any suggestions?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;input StudyID $1-2 CaseID $4-6 m2blue $8-12 q1green $14-18 k5orange $20-24;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;AA AA1 0-No&amp;nbsp; 0-No&amp;nbsp; 1-Yes&lt;/P&gt;&lt;P&gt;BB BB1 0-No&amp;nbsp; 0-No&amp;nbsp; 0-No &lt;/P&gt;&lt;P&gt;CC CC1 1-Yes 0-No&amp;nbsp; 1-Yes&lt;/P&gt;&lt;P&gt;DD DD1 0-No&amp;nbsp; 1-Yes 1-Yes&lt;/P&gt;&lt;P&gt;EE EE1 1-Yes 1-Yes 1-Yes&lt;/P&gt;&lt;P&gt;FF FF1 0-No&amp;nbsp; 0-No&amp;nbsp; 0-No&lt;/P&gt;&lt;P&gt;GG GG1 0-No&amp;nbsp; 0-No&amp;nbsp; 0-No&lt;/P&gt;&lt;P&gt;HH HH1 0-No&amp;nbsp; 1-Yes 0-No&lt;/P&gt;&lt;P&gt;II II1 1-Yes 0-No&amp;nbsp; 0-No&lt;/P&gt;&lt;P&gt;JJ JJ1 1-Yes 0-No&amp;nbsp; 1-Yes&lt;/P&gt;&lt;P&gt;;;&lt;/P&gt;&lt;P&gt;run;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data bugn;&lt;/P&gt;&lt;P&gt;input vd $ 1-40;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;m2blue&lt;/P&gt;&lt;P&gt;q1green&lt;/P&gt;&lt;P&gt;k5orange&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;set bugn end=last;&lt;/P&gt;&lt;P&gt;call symput('vd'||left(put(_n_,3.)),vd);&lt;/P&gt;&lt;P&gt;if last then call symput('bugn',_n_);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;options mprint;&lt;/P&gt;&lt;P&gt;%macro loop;&lt;/P&gt;&lt;P&gt;%do i=1 %to &amp;amp;bugn;&lt;/P&gt;&lt;P&gt;%let ti=%cmpres(&amp;amp;bug&amp;amp;i);&lt;/P&gt;&lt;P&gt;data two;&lt;/P&gt;&lt;P&gt;vd="&amp;amp;&amp;amp;vd&amp;amp;i";&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let vd=&amp;amp;&amp;amp;vd&amp;amp;i;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;set have (rename=(&amp;amp;vd=&amp;amp;vd._old));&lt;/P&gt;&lt;P&gt;format &amp;amp;vd 1.;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %do i=1 %to &amp;amp;bugn;&lt;/P&gt;&lt;P&gt;if substr(&amp;amp;vd._old,1,1) = '0' then &amp;amp;vd=0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else if substr(&amp;amp;vd._old,1,1) = '1' then &amp;amp;vd=1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; retain &amp;amp;vd;&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;&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;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; keep &amp;amp;vd; &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;%end;&lt;/P&gt;&lt;P&gt;%mend loop;&lt;/P&gt;&lt;P&gt;%loop;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Oct 2014 18:25:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Macro-to-create-new-variables/m-p/176980#M33870</guid>
      <dc:creator>sophia_SAS</dc:creator>
      <dc:date>2014-10-08T18:25:10Z</dc:date>
    </item>
    <item>
      <title>Re: Using Macro to create new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Macro-to-create-new-variables/m-p/176981#M33871</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Are you originally reading from a text file or a SAS data set?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Oct 2014 18:55:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Macro-to-create-new-variables/m-p/176981#M33871</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2014-10-08T18:55:37Z</dc:date>
    </item>
    <item>
      <title>Re: Using Macro to create new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Macro-to-create-new-variables/m-p/176982#M33872</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The data is originally from a text file.&amp;nbsp; What would be the difference if it was from a SAS data set?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Oct 2014 18:58:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Macro-to-create-new-variables/m-p/176982#M33872</guid>
      <dc:creator>sophia_SAS</dc:creator>
      <dc:date>2014-10-08T18:58:25Z</dc:date>
    </item>
    <item>
      <title>Re: Using Macro to create new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Macro-to-create-new-variables/m-p/176983#M33873</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Fix it in the original import step rather than try and do it afterwards.&amp;nbsp; i.e. fix it before it's broken. &lt;/P&gt;&lt;P&gt;Can you post a small sample of the text file or is the data step above representative? If so, what would you want the output to be. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Oct 2014 19:05:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Macro-to-create-new-variables/m-p/176983#M33873</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2014-10-08T19:05:37Z</dc:date>
    </item>
    <item>
      <title>Re: Using Macro to create new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Macro-to-create-new-variables/m-p/176984#M33874</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;With a text file you can specify a custom format on reading the data.&lt;/P&gt;&lt;P&gt;I am guessing that you want 1 for Yes and 0 for No in your final form.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Proc format;&lt;/P&gt;&lt;P&gt;invalue MyYesNo&lt;/P&gt;&lt;P&gt;'1-Yes' = 1&lt;/P&gt;&lt;P&gt;'0-No' = 0&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; infile "your file name to read" &amp;lt;options to read&amp;gt;; /* if you used proc import you can look at the resulting code in the log to get this */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; informat&amp;nbsp; m2blue q1green&amp;nbsp; k5orange&amp;nbsp; MyYesNo. ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; input StudyID $1-2 CaseID $4-6 m2blue 8-12 q1green 14-18 k5orange 20-24; /* what ever the input statement needs*/&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Oct 2014 19:48:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Macro-to-create-new-variables/m-p/176984#M33874</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2014-10-08T19:48:05Z</dc:date>
    </item>
    <item>
      <title>Re: Using Macro to create new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Macro-to-create-new-variables/m-p/176985#M33875</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You could just change your INPUT statement and avoid writing macros entirely:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;length dummy $ 1;&lt;/P&gt;&lt;P&gt;drop dummy;&lt;/P&gt;&lt;P&gt;input StudyID $1-2 CaseID $4-6 m2blue : 1. dummy q1green : 1. dummy k5orange : 1.;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Oct 2014 21:19:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Macro-to-create-new-variables/m-p/176985#M33875</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2014-10-08T21:19:12Z</dc:date>
    </item>
    <item>
      <title>Re: Using Macro to create new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Macro-to-create-new-variables/m-p/176986#M33876</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks!&amp;nbsp; This worked great and was a lot easier than a macro.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Oct 2014 14:29:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Macro-to-create-new-variables/m-p/176986#M33876</guid>
      <dc:creator>sophia_SAS</dc:creator>
      <dc:date>2014-10-09T14:29:04Z</dc:date>
    </item>
    <item>
      <title>Re: Using Macro to create new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Macro-to-create-new-variables/m-p/176987#M33877</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Please mark the question as answered so people know we don't need to check whether this still needs an answer.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Oct 2014 15:34:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Macro-to-create-new-variables/m-p/176987#M33877</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2014-10-09T15:34:30Z</dc:date>
    </item>
    <item>
      <title>Re: Using Macro to create new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Macro-to-create-new-variables/m-p/176988#M33878</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Astounding,&lt;/P&gt;&lt;P&gt;what does it means the ':' carachter in the input statement, before the number?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Oct 2014 18:49:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Macro-to-create-new-variables/m-p/176988#M33878</guid>
      <dc:creator>Rakeon</dc:creator>
      <dc:date>2014-10-09T18:49:59Z</dc:date>
    </item>
  </channel>
</rss>

