<?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 short the data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-short-the-data/m-p/141042#M28368</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for ur ans, Ur ans is correct , but just u r not using retain to hold value. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 12 Mar 2014 11:59:25 GMT</pubDate>
    <dc:creator>Aman4SAS</dc:creator>
    <dc:date>2014-03-12T11:59:25Z</dc:date>
    <item>
      <title>Macro to short the data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-short-the-data/m-p/141035#M28361</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;proc sort data=short_state_soc22 ; by state; run;&lt;/P&gt;&lt;P&gt;%macro srt();&lt;/P&gt;&lt;P&gt;data wide_state;&lt;/P&gt;&lt;P&gt;set short_state_soc22;&lt;/P&gt;&lt;P&gt;by state;&lt;/P&gt;&lt;P&gt;array soc22{22} occ_11 occ_13 occ_15 occ_17 occ_19 occ_21 occ_23 occ_25 occ_27 occ_29 occ_31 occ_33 occ_35 occ_37 occ_39 occ_41 occ_43 occ_45 occ_47 occ_49 occ_51 occ_53 ;&lt;/P&gt;&lt;P&gt;retain soc22; &lt;/P&gt;&lt;P&gt;%do i=11 %to 53 %by 2;&lt;/P&gt;&lt;P&gt;%if soc_22 ="&amp;amp;i" %then soc22[occ_&amp;amp;i]=count;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%if last.state=1 %then output;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%mend srt;&lt;/P&gt;&lt;P&gt;%srt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to chage the dataset wide as State occ_11 occ_13 occ_15 ..... &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Programe is running but giving missing values. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can anyone help me on this.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Mar 2014 10:42:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-short-the-data/m-p/141035#M28361</guid>
      <dc:creator>Aman4SAS</dc:creator>
      <dc:date>2014-03-12T10:42:35Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to short the data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-short-the-data/m-p/141036#M28362</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Do you mean you want to transpose the data out into wide?&amp;nbsp; If so use proc transpose:&lt;/P&gt;&lt;P&gt;proc sort data=a.short_state_soc22 ; by state; run;&lt;/P&gt;&lt;P&gt;proc transpose data=a.short_state_soc22 out=wide prefix=occ_;&lt;BR /&gt;&amp;nbsp; by state;&lt;BR /&gt;&amp;nbsp; var count;&lt;BR /&gt;&amp;nbsp; id soc_22;&lt;BR /&gt;&amp;nbsp; idlabel soc_22;&lt;BR /&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Mar 2014 11:02:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-short-the-data/m-p/141036#M28362</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2014-03-12T11:02:56Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to short the data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-short-the-data/m-p/141037#M28363</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;yes i can do that by transpose , but my question y its showing missing value and y cant we do it by array?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Mar 2014 11:08:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-short-the-data/m-p/141037#M28363</guid>
      <dc:creator>Aman4SAS</dc:creator>
      <dc:date>2014-03-12T11:08:15Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to short the data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-short-the-data/m-p/141038#M28364</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;%if soc_22 ="&amp;amp;i" %then soc22[occ_&amp;amp;i]=count;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In this macro statement, soc_22 is not a variable, but a value!&lt;/P&gt;&lt;P&gt;Therefore you are comparing (the string!) soc_22 to "11", "13" and so on, which is never true.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The same goes for&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%if last.state&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;last.state is just a string when the macro executes (long before the data step even is compiled and starts) and the whole construct has no meaning.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Mar 2014 11:20:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-short-the-data/m-p/141038#M28364</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2014-03-12T11:20:12Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to short the data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-short-the-data/m-p/141039#M28365</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;ahhh, Thanks, i was missing that.&lt;/P&gt;&lt;P&gt;Is there any way to resolve it in the same manner.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Mar 2014 11:32:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-short-the-data/m-p/141039#M28365</guid>
      <dc:creator>Aman4SAS</dc:creator>
      <dc:date>2014-03-12T11:32:13Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to short the data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-short-the-data/m-p/141040#M28366</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry, having issues posting.&amp;nbsp; KurtBremser has pointed out some bits and I think there are other items which are going wrong.&amp;nbsp; Try the below code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data wide_state (drop=i x);&lt;/P&gt;&lt;P&gt;&amp;nbsp; set a.short_state_soc22;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by state;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array occ{22} occ_11 occ_13 occ_15 occ_17 occ_19 occ_21 occ_23 occ_25 occ_27 occ_29 occ_31 occ_33 occ_35 occ_37 occ_39 occ_41 occ_43 occ_45 occ_47 occ_49 occ_51 occ_53;&lt;/P&gt;&lt;P&gt;&amp;nbsp; retain occ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do i=11 to 53 by 2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if i=11 then x=1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else x=x+1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if soc_22=i then occ{x}=count;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if last.state then output;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Mar 2014 11:41:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-short-the-data/m-p/141040#M28366</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2014-03-12T11:41:56Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to short the data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-short-the-data/m-p/141041#M28367</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What you want is this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort data=short_state_soc22 ; by state; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data wide_state (drop=soc soc_22 count i);&lt;/P&gt;&lt;P&gt;set short_state_soc22;&lt;/P&gt;&lt;P&gt;by state;&lt;/P&gt;&lt;P&gt;array soc22{22} occ_11 occ_13 occ_15 occ_17 occ_19 occ_21 occ_23 occ_25 occ_27 occ_29 occ_31 occ_33 occ_35 occ_37 occ_39 occ_41 occ_43 occ_45 occ_47 occ_49 occ_51 occ_53 ;&lt;/P&gt;&lt;P&gt;retain soc22;&lt;/P&gt;&lt;P&gt;if first.state then do i = 1 to 22; soc22&lt;I&gt; = .; end;&lt;/I&gt;&lt;/P&gt;&lt;P&gt;soc22[(soc_22-9)/2] = count;&lt;/P&gt;&lt;P&gt;if last.state then output;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Mar 2014 11:51:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-short-the-data/m-p/141041#M28367</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2014-03-12T11:51:06Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to short the data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-short-the-data/m-p/141042#M28368</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for ur ans, Ur ans is correct , but just u r not using retain to hold value. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Mar 2014 11:59:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-short-the-data/m-p/141042#M28368</guid>
      <dc:creator>Aman4SAS</dc:creator>
      <dc:date>2014-03-12T11:59:25Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to short the data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-short-the-data/m-p/141043#M28369</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Mar 2014 11:59:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-short-the-data/m-p/141043#M28369</guid>
      <dc:creator>Aman4SAS</dc:creator>
      <dc:date>2014-03-12T11:59:42Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to short the data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-short-the-data/m-p/141044#M28370</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;But if i use in this manner , in this case soc_22 must have value its not a part of marco , is it?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;proc sort data=short_state_soc22 ; by state; run;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%macro srt();&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;data wide_state;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;set short_state_soc22;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;by state;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;array soc22{22} occ_11 occ_13 occ_15 occ_17 occ_19 occ_21 occ_23 occ_25 occ_27 occ_29 occ_31 occ_33 occ_35 occ_37 occ_39 occ_41 occ_43 occ_45 occ_47 occ_49 occ_51 occ_53 ;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;%do i=11 %to 53 %by 2;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;retain soc22;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;if soc_22 ="&amp;amp;i" %then soc22[occ_&amp;amp;i]=count;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%end;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;if last.state=1 %then output;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;run;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%mend srt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%srt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Mar 2014 13:01:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-short-the-data/m-p/141044#M28370</guid>
      <dc:creator>Aman4SAS</dc:creator>
      <dc:date>2014-03-12T13:01:08Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to short the data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-short-the-data/m-p/141045#M28371</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;First, your example has 2 seemingly small but significant errors:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;proc sort data=short_state_soc22 ; by state; run;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;%macro srt();&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;data wide_state;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;set short_state_soc22;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;by state;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;array soc22{22} occ_11 occ_13 occ_15 occ_17 occ_19 occ_21 occ_23 occ_25 occ_27 occ_29 occ_31 occ_33 occ_35 occ_37 occ_39 occ_41 occ_43 occ_45 occ_47 occ_49 occ_51 occ_53 ;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-size: 10pt;"&gt;%do i=11 %to 53 %by 2;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;retain soc22;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;if soc_22 ="&amp;amp;i" &lt;SPAN style="text-decoration: line-through;"&gt;&lt;SPAN style="text-decoration: underline;"&gt;&lt;EM&gt;%&lt;/EM&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;then soc22[occ_&amp;amp;i]=count; *"%then" is wrong, should be "then";&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;%end;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;if last.state=1 &lt;SPAN style="text-decoration: line-through;"&gt;&lt;SPAN style="text-decoration: underline;"&gt;&lt;EM&gt;%&lt;/EM&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;then output; *"%then" is wrong, should be "then";&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;run;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;%mend srt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;%srt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P&gt;Remember that the macro facility is just a code generator. What your macro does looks like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data wide_state;&lt;/P&gt;&lt;P&gt;set short_state_soc22;&lt;/P&gt;&lt;P&gt;by state;&lt;/P&gt;&lt;P&gt;array soc22{22} occ_11 occ_13 occ_15 occ_17 occ_19 occ_21 occ_23 occ_25 occ_27 occ_29 occ_31 occ_33 occ_35 occ_37 occ_39 occ_41 occ_43 occ_45 occ_47 occ_49 occ_51 occ_53 ;&lt;/P&gt;&lt;P&gt;retain soc22;&lt;/P&gt;&lt;P&gt;if soc_22 ="11" then soc22[occ_11]=count;&lt;/P&gt;&lt;P&gt;retain soc22;&lt;/P&gt;&lt;P&gt;if soc_22 ="13" then soc22[occ_13]=count;&lt;/P&gt;&lt;P&gt;retain soc22;&lt;/P&gt;&lt;P&gt;if soc_22 ="15" then soc22[occ_15]=count;&lt;/P&gt;&lt;P&gt;retain soc22;&lt;/P&gt;&lt;P&gt;if soc_22 ="17" then soc22[occ_17]=count;&lt;/P&gt;&lt;P&gt;retain soc22;&lt;/P&gt;&lt;P&gt;if soc_22 ="19" then soc22[occ_19]=count;&lt;/P&gt;&lt;P&gt;retain soc22;&lt;/P&gt;&lt;P&gt;if soc_22 ="21" then soc22[occ_21]=count;&lt;/P&gt;&lt;P&gt;retain soc22;&lt;/P&gt;&lt;P&gt;if soc_22 ="23" then soc22[occ_23]=count;&lt;/P&gt;&lt;P&gt;retain soc22;&lt;/P&gt;&lt;P&gt;if soc_22 ="25" then soc22[occ_25]=count;&lt;/P&gt;&lt;P&gt;retain soc22;&lt;/P&gt;&lt;P&gt;if soc_22 ="27" then soc22[occ_27]=count;&lt;/P&gt;&lt;P&gt;retain soc22;&lt;/P&gt;&lt;P&gt;if soc_22 ="29" then soc22[occ_29]=count;&lt;/P&gt;&lt;P&gt;retain soc22;&lt;/P&gt;&lt;P&gt;if soc_22 ="31" then soc22[occ_31]=count;&lt;/P&gt;&lt;P&gt;retain soc22;&lt;/P&gt;&lt;P&gt;if soc_22 ="33" then soc22[occ_33]=count;&lt;/P&gt;&lt;P&gt;retain soc22;&lt;/P&gt;&lt;P&gt;if soc_22 ="35" then soc22[occ_35]=count;&lt;/P&gt;&lt;P&gt;retain soc22;&lt;/P&gt;&lt;P&gt;if soc_22 ="37" then soc22[occ_37]=count;&lt;/P&gt;&lt;P&gt;retain soc22;&lt;/P&gt;&lt;P&gt;if soc_22 ="39" then soc22[occ_39]=count;&lt;/P&gt;&lt;P&gt;retain soc22;&lt;/P&gt;&lt;P&gt;if soc_22 ="41" then soc22[occ_41]=count;&lt;/P&gt;&lt;P&gt;retain soc22;&lt;/P&gt;&lt;P&gt;if soc_22 ="43" then soc22[occ_43]=count;&lt;/P&gt;&lt;P&gt;retain soc22;&lt;/P&gt;&lt;P&gt;if soc_22 ="45" then soc22[occ_45]=count;&lt;/P&gt;&lt;P&gt;retain soc22;&lt;/P&gt;&lt;P&gt;if soc_22 ="47" then soc22[occ_47]=count;&lt;/P&gt;&lt;P&gt;retain soc22;&lt;/P&gt;&lt;P&gt;if soc_22 ="49" then soc22[occ_49]=count;&lt;/P&gt;&lt;P&gt;retain soc22;&lt;/P&gt;&lt;P&gt;if soc_22 ="51" then soc22[occ_51]=count;&lt;/P&gt;&lt;P&gt;retain soc22;&lt;/P&gt;&lt;P&gt;if soc_22 ="53" then soc22[occ_53]=count;&lt;/P&gt;&lt;P&gt;if last.state=1 then output;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Decide for yourself which code is more efficient and readable!&lt;/P&gt;&lt;P&gt;All those ifs eat a lot of CPU power, BTW.&lt;/P&gt;&lt;P&gt;The macro facility lets you create dynamic code. If the code remains static, do it in the data step itself.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edit: replaced %then with then&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Mar 2014 13:20:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-short-the-data/m-p/141045#M28371</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2014-03-12T13:20:21Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to short the data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-short-the-data/m-p/141046#M28372</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So you want to roll the values up into an array.&amp;nbsp;&amp;nbsp; To do what you want you could use this simple data step.&amp;nbsp; Nesting the SET statement inside the DO loop eliminates the need to RETAIN the variables or add an explicit OUTPUT statement to keep only one observation per state.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data want ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; do until (last.state) ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set dl.short_state_soc22;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; by state;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; array occ occ_01 - occ_053 ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if 1&amp;lt;= soc_22 &amp;lt;= dim(occ) then occ(soc_22) = count;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; keep state occ_11 occ_13 occ_15 occ_17 occ_19 occ_21 occ_23&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; occ_25 occ_27 occ_29 occ_31 occ_33 occ_35 occ_37 occ_39 occ_41&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; occ_43 occ_45 occ_47 occ_49 occ_51 occ_53&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you want the columns that do not have counts to be zero instead of missing then you will need to add code to set them to zero.&amp;nbsp; One way is to add another do loop after the first one.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;do _n_ = 1 to dim(occ);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt; occ(_n_) = sum(occ(_n_),0); &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am not sure why are you only want to keep the odd numbers between 11 and 53?&amp;nbsp; If it is because those are the only values in your data then you could make that decision dynamic by using SQL to query the data and generate the list to keep. It could also determine the upper bound on your array.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You could query the data to get the maximum value of SOC_22 and the distinct list of values that are present.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;proc sql noprint ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; select max(soc_22) into :max separated by ' '&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; from dl.short_state_soc22&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; select distinct catx('_','occ',soc_22)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; into :keeplist separated by ' '&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; from dl.short_state_soc22&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data want ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; do until (last.state) ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set dl.short_state_soc22;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; by state;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; array occ occ_01 - occ_&amp;amp;max;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if 1&amp;lt;= soc_22 &amp;lt;= dim(occ) then occ(soc_22) = count;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; keep state &amp;amp;keeplist ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Mar 2014 14:00:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-short-the-data/m-p/141046#M28372</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2014-03-12T14:00:24Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to short the data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-short-the-data/m-p/141047#M28373</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks and my apology for taking you too much time, &lt;/P&gt;&lt;P&gt;as u have already solved my problem in ur prior notes, Thanks.&lt;/P&gt;&lt;P&gt;But now my concern is y its giving error &lt;/P&gt;&lt;P&gt;"&lt;STRONG&gt;Array subscript out of range at line 3 column 37&lt;/STRONG&gt;" , As per saving time n ur suggestion its should not be use in real time scenario. &lt;/P&gt;&lt;P&gt;but willing to clear error. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro srt();&lt;/P&gt;&lt;P&gt;data wide_state;&lt;/P&gt;&lt;P&gt;set short_state_soc22;&lt;/P&gt;&lt;P&gt;by state;&lt;/P&gt;&lt;P&gt;array soc22{22} occ_11 occ_13 occ_15 occ_17 occ_19 occ_21 occ_23 occ_25 occ_27 occ_29 occ_31 occ_33 occ_35 occ_37 occ_39 occ_41 occ_43 occ_45 occ_47 occ_49 occ_51 occ_53 ;&lt;/P&gt;&lt;P&gt;%do i=11 %to 53 %by 2;&lt;/P&gt;&lt;P&gt;retain soc22;&lt;/P&gt;&lt;P&gt;if soc_22 ="&amp;amp;i" then soc22[occ_&amp;amp;i]=count; &lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;if last.state then output; &lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%mend srt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%srt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Mar 2014 06:16:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-short-the-data/m-p/141047#M28373</guid>
      <dc:creator>Aman4SAS</dc:creator>
      <dc:date>2014-03-13T06:16:12Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to short the data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-short-the-data/m-p/141048#M28374</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You are indexing the soc22 array with the _contents_ of occ_&amp;amp;i. If that is less than 1 or more than 22 -&amp;gt; poof!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Mar 2014 06:30:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-short-the-data/m-p/141048#M28374</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2014-03-13T06:30:45Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to short the data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-short-the-data/m-p/141049#M28375</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am not passing ref , i m directly passing array variable name, &lt;/P&gt;&lt;P&gt;i.e when soc_22 is 11 then soc22[occ_11]= count; /* its always in between 11-53 by 2&lt;/P&gt;&lt;P&gt;%macro srt();&lt;/P&gt;&lt;P&gt;data wide_state;&lt;/P&gt;&lt;P&gt;set short_state_soc22;&lt;/P&gt;&lt;P&gt;by state;&lt;/P&gt;&lt;P&gt;array soc22 occ_11 occ_13 occ_15 occ_17 occ_19 occ_21 occ_23 occ_25 occ_27 occ_29 occ_31 occ_33 occ_35 occ_37 occ_39 occ_41 occ_43 occ_45 occ_47 occ_49 occ_51 occ_53 ;&lt;/P&gt;&lt;P&gt;%do i=11 %to 53 %by 2;&lt;/P&gt;&lt;P&gt;retain soc22;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if soc_22 ="&amp;amp;i" then soc22[occ_&amp;amp;i]=count; *"%then" is wrong, should be "then";&lt;/P&gt;&lt;P&gt;%put &amp;amp;i;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;if last.state then output; *"%then" is wrong, should be "then";&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%mend srt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%srt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Mar 2014 07:15:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-short-the-data/m-p/141049#M28375</guid>
      <dc:creator>Aman4SAS</dc:creator>
      <dc:date>2014-03-13T07:15:25Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to short the data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-short-the-data/m-p/141050#M28376</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You MUST reference an array element by a NUMERICAL index, NOT by its name outside of the array:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;From the SAS documentation:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="strong"&gt;subscript&lt;/SPAN&gt; &lt;/P&gt;&lt;P&gt;&lt;A name="a001379845"&gt; &lt;/A&gt;specifies the subscript, which can be a &lt;STRONG&gt;numeric constant&lt;/STRONG&gt;, the name of a variable whose &lt;STRONG&gt;value is the number,&lt;/STRONG&gt; a SAS numeric expression, or an asterisk (*).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In your code, the numerical index is taken from the contents of any of the occ_* variables, which causes the crash when it is not between 1 and 22.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Mar 2014 07:24:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-short-the-data/m-p/141050#M28376</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2014-03-13T07:24:55Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to short the data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-short-the-data/m-p/141051#M28377</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Okk. Got it, Thanks a lot. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Mar 2014 07:30:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-short-the-data/m-p/141051#M28377</guid>
      <dc:creator>Aman4SAS</dc:creator>
      <dc:date>2014-03-13T07:30:18Z</dc:date>
    </item>
  </channel>
</rss>

