<?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: Convert SPSS macro to SAS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Convert-SPSS-macro-to-SAS/m-p/136945#M295844</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;A description of how it "doesn't seem to work" is a good idea.&lt;/P&gt;&lt;P&gt;With that in mind, I suspect these lines&lt;/P&gt;&lt;P&gt; SUBST("Event_"&amp;amp;i,"_type") = 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; SUBST("Event_"&amp;amp;i,"_date") = A_date;&lt;/P&gt;&lt;P&gt;are generating an error and it maybe something about an undefined array reference.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The code you are using would replace the outputset NR times.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think you can get this with array processing and if you can live slightly different variable names such as event_type_1 instead of event_1_type it gets pretty easy.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro eventrecode(nr);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data UT_PREPARED2;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set UT_PREPAREd;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; array type Event_type_1 - Event_type_&amp;amp;nr;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; array date Event_date_1 - Event_date_&amp;amp;nr;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do I = 1 to dim(type);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if A_rank = I then do; /* the do indicates a block of statements to execute when the condition is true, you were missing this in your and only the first bit was attempting to execute*/&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; type&lt;I&gt; = 1;&lt;/I&gt;&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; date&lt;I&gt; = A_date;&lt;/I&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end; /* ends the if then do block*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end; /* ends loop for I*/&lt;/P&gt;&lt;P&gt;&amp;nbsp; run; /* very good idea to explicitly indicate the end of a data step, especially when using macros*/&lt;/P&gt;&lt;P&gt;&amp;nbsp; %End;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%mend eventrecode;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HINT: Before even attempting a macro make sure you have the code running as intended, the data step I indicated you could replace the two values of &amp;amp;nr in the body with 3 and should run.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm not sure if I remember the function SUBST from SPSS, but it does not exist in SAS. There are also a number of functions that perform different types of concatenation: CATS, CATT, CATX and CATQ plus other operations on character values.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 04 Dec 2014 20:32:26 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2014-12-04T20:32:26Z</dc:date>
    <item>
      <title>Convert SPSS macro to SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-SPSS-macro-to-SAS/m-p/136944#M295843</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi guys,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm switching to SAS from SPSS for a new project, but I struggle with converting an SPSS Macro to SAS. I was wondering if anyone could help me. This macro checks if a certain type of event (A thru Z) is ranked first, second, etc and the puts the type of event in the event_1_type and the corresponding date in event_1_date.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Current SPSS macro&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DEFINE !eventrecode (nr = !CMDEND)&lt;/P&gt;&lt;P&gt;!DO !eventnr=1 !TO !nr&lt;/P&gt;&lt;P&gt;Do if A_rank = !eventnr.&lt;/P&gt;&lt;P&gt;&amp;nbsp; compute !CONCAT("Event_",!eventnr,"_type")=1.&lt;/P&gt;&lt;P&gt;&amp;nbsp; compute !CONCAT("Event_",!eventnr, "_date")=A_date.&lt;/P&gt;&lt;P&gt;End if.&lt;/P&gt;&lt;P&gt;!Doend&lt;/P&gt;&lt;P&gt;Execute.&lt;/P&gt;&lt;P&gt;!Enddefine.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;!eventrecode n3=3&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My SAS attempt:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro eventrecode(nr);&lt;/P&gt;&lt;P&gt;%do i=1 %to &amp;amp;nr;&lt;/P&gt;&lt;P&gt;data UT_PREPARED2;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set UT_PREPAREd;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if A_rank = &amp;amp;i then;&lt;/P&gt;&lt;P&gt;&amp;nbsp; SUBST("Event_"&amp;amp;i,"_type") = 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; SUBST("Event_"&amp;amp;i,"_date") = A_date;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %End;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%mend eventrecode;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%eventrecode(3)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But that doesn't seem to work. Any help would be greatly appreciated!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Dec 2014 19:45:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-SPSS-macro-to-SAS/m-p/136944#M295843</guid>
      <dc:creator>KoenN</dc:creator>
      <dc:date>2014-12-04T19:45:31Z</dc:date>
    </item>
    <item>
      <title>Re: Convert SPSS macro to SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-SPSS-macro-to-SAS/m-p/136945#M295844</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;A description of how it "doesn't seem to work" is a good idea.&lt;/P&gt;&lt;P&gt;With that in mind, I suspect these lines&lt;/P&gt;&lt;P&gt; SUBST("Event_"&amp;amp;i,"_type") = 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; SUBST("Event_"&amp;amp;i,"_date") = A_date;&lt;/P&gt;&lt;P&gt;are generating an error and it maybe something about an undefined array reference.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The code you are using would replace the outputset NR times.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think you can get this with array processing and if you can live slightly different variable names such as event_type_1 instead of event_1_type it gets pretty easy.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro eventrecode(nr);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data UT_PREPARED2;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set UT_PREPAREd;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; array type Event_type_1 - Event_type_&amp;amp;nr;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; array date Event_date_1 - Event_date_&amp;amp;nr;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do I = 1 to dim(type);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if A_rank = I then do; /* the do indicates a block of statements to execute when the condition is true, you were missing this in your and only the first bit was attempting to execute*/&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; type&lt;I&gt; = 1;&lt;/I&gt;&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; date&lt;I&gt; = A_date;&lt;/I&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end; /* ends the if then do block*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end; /* ends loop for I*/&lt;/P&gt;&lt;P&gt;&amp;nbsp; run; /* very good idea to explicitly indicate the end of a data step, especially when using macros*/&lt;/P&gt;&lt;P&gt;&amp;nbsp; %End;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%mend eventrecode;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HINT: Before even attempting a macro make sure you have the code running as intended, the data step I indicated you could replace the two values of &amp;amp;nr in the body with 3 and should run.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm not sure if I remember the function SUBST from SPSS, but it does not exist in SAS. There are also a number of functions that perform different types of concatenation: CATS, CATT, CATX and CATQ plus other operations on character values.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Dec 2014 20:32:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-SPSS-macro-to-SAS/m-p/136945#M295844</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2014-12-04T20:32:26Z</dc:date>
    </item>
    <item>
      <title>Re: Convert SPSS macro to SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-SPSS-macro-to-SAS/m-p/136946#M295845</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Are you just trying to do something like the following?:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro eventrecode(nr);&lt;/P&gt;&lt;P&gt;&amp;nbsp; %do i=1 %to &amp;amp;nr.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if a_rank=&amp;amp;i. then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; event_&amp;amp;i._type=1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; event_&amp;amp;i._date=a_date;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;%mend eventrecode;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input a_rank a_date date9.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; cards;&lt;/P&gt;&lt;P&gt;1 04dec2014&lt;/P&gt;&lt;P&gt;1 04dec2014&lt;/P&gt;&lt;P&gt;2 04dec2014&lt;/P&gt;&lt;P&gt;2 04dec2014&lt;/P&gt;&lt;P&gt;3 04dec2014&lt;/P&gt;&lt;P&gt;3 04dec2014&lt;/P&gt;&lt;P&gt;4 04dec2014&lt;/P&gt;&lt;P&gt;4 04dec2014&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;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %eventrecode(3)&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Dec 2014 22:47:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-SPSS-macro-to-SAS/m-p/136946#M295845</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2014-12-04T22:47:35Z</dc:date>
    </item>
    <item>
      <title>Re: Convert SPSS macro to SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-SPSS-macro-to-SAS/m-p/136947#M295846</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, this did the trick. The syntax is somewhat more complicatied after the if-statement, but I've just editted my original SPSS syntax and it all works. The . after &amp;amp;i is very neat, love it! Thank you so much!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Dec 2014 09:59:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-SPSS-macro-to-SAS/m-p/136947#M295846</guid>
      <dc:creator>KoenN</dc:creator>
      <dc:date>2014-12-08T09:59:28Z</dc:date>
    </item>
    <item>
      <title>Re: Convert SPSS macro to SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-SPSS-macro-to-SAS/m-p/136948#M295847</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you for your help! I'll keep it in mind to better describe 'it doesn't work' for the next time, you're absolutely right.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Dec 2014 10:00:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-SPSS-macro-to-SAS/m-p/136948#M295847</guid>
      <dc:creator>KoenN</dc:creator>
      <dc:date>2014-12-08T10:00:46Z</dc:date>
    </item>
  </channel>
</rss>

