<?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 keep values with in macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-macro-variables/m-p/576775#M163306</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/209685"&gt;@thanikondharish&lt;/a&gt;&amp;nbsp;:&lt;/P&gt;
&lt;P&gt;Not quite sure I understand your question. How this other macro variable you're talking about is supposed to be called? Which are the other macro variables whose count it should contain?&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 26 Jul 2019 01:11:25 GMT</pubDate>
    <dc:creator>hashman</dc:creator>
    <dc:date>2019-07-26T01:11:25Z</dc:date>
    <item>
      <title>How to create macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-macro-variables/m-p/576168#M163051</link>
      <description>&lt;P&gt;data test;&lt;BR /&gt;input zone $ state$ brnch$ sales;&lt;BR /&gt;cards;&lt;BR /&gt;SOUTH AP VZG 254&lt;BR /&gt;SOUTH AP TRP 247&lt;BR /&gt;SOUTH AP GUN 321&lt;BR /&gt;SOUTH TS HYD 147&lt;BR /&gt;SOUTH TS WGL 315&lt;BR /&gt;NORTH MH MUM 254&lt;BR /&gt;NORTH MH PUN 247&lt;BR /&gt;NORTH GJ AHM 323&lt;BR /&gt;NORTH DL NCR 148&lt;BR /&gt;NORTH DL NOD 319&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;I have above dataset . How to create macro variales like see below examples..&lt;/P&gt;
&lt;P&gt;ex1:&lt;/P&gt;
&lt;P&gt;q1)how to create macro variable for zone distinct count&lt;/P&gt;
&lt;P&gt;Ans:&amp;nbsp; &amp;nbsp;2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;q2)how to create macro variable for&amp;nbsp;distinct values of zone&lt;/P&gt;
&lt;P&gt;Ans:&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;zone1:SOUTH&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ZONE2:NORTH&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;q3)how to create macro variable for distinct count of state with in zone&lt;/P&gt;
&lt;P&gt;Ans:&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;SOUTH_state_1:&amp;nbsp; &amp;nbsp; AP&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SOUTH_state_2:&amp;nbsp; &amp;nbsp; TS&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;NORTH _state_1:&amp;nbsp; &amp;nbsp; MH&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;NORTH _state_2:&amp;nbsp; &amp;nbsp; GJ&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;NORTH _state_3&amp;nbsp; &amp;nbsp; :DL&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;q3)how to create macro variable for distinct count of branch with in zone and state&lt;/P&gt;
&lt;P&gt;Ans:&amp;nbsp; &amp;nbsp; &amp;nbsp; SOUTH_AP_branch1:&amp;nbsp; VZG&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SOUTH_AP_branch2:&amp;nbsp; &amp;nbsp;TRP&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;SOUTH_AP_branch3:&amp;nbsp; GUN&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SOUTH_state_TS_branch1:&amp;nbsp; &amp;nbsp;HYD&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SOUTH_state_TS_branch2:&amp;nbsp; &amp;nbsp;WGL&lt;/P&gt;
&lt;P&gt;...........................................&lt;/P&gt;
&lt;P&gt;how to keep in macro&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jul 2019 15:08:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-macro-variables/m-p/576168#M163051</guid>
      <dc:creator>thanikondharish</dc:creator>
      <dc:date>2019-07-24T15:08:44Z</dc:date>
    </item>
    <item>
      <title>Re: HOW TO CREATE MACRO VARIABLES</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-macro-variables/m-p/576171#M163052</link>
      <description>&lt;P&gt;What did you try?&amp;nbsp; What success did you have?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS: Use the Insert Code button on the menu (look like {i}) when inserting monospaced text.&amp;nbsp; &amp;nbsp;That will keep the formatting and prevent the smileys.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jul 2019 14:20:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-macro-variables/m-p/576171#M163052</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-07-24T14:20:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to create macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-macro-variables/m-p/576209#M163073</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;
&lt;P&gt;how to keep in macro&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What does that mean?&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jul 2019 15:33:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-macro-variables/m-p/576209#M163073</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-07-24T15:33:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to create macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-macro-variables/m-p/576249#M163087</link>
      <description>&lt;P&gt;Looks like homework you should be able to do on your own, with a little help from the documentation. Hint: look for call symput() and call symputx().&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jul 2019 16:54:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-macro-variables/m-p/576249#M163087</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-07-24T16:54:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to create macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-macro-variables/m-p/576395#M163141</link>
      <description>&lt;P&gt;And Proc Freq with the OUT= tables option.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jul 2019 22:34:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-macro-variables/m-p/576395#M163141</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-07-24T22:34:54Z</dc:date>
    </item>
    <item>
      <title>how to keep values with in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-macro-variables/m-p/576587#M163261</link>
      <description>&lt;P&gt;&lt;SPAN&gt;data test;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;input zone $ state$ brnch$ sales;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;cards;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;SOUTH AP VZG 254&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;SOUTH AP TRP 247&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;SOUTH AP GUN 321&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;SOUTH TS HYD 147&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;SOUTH TS WGL 315&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;NORTH MH MUM 254&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;NORTH MH PUN 247&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;NORTH GJ AHM 323&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;NORTH DL NCR 148&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;NORTH DL NOD 319&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;q1)how to create macro variable for zone distinct count&lt;/P&gt;&lt;P&gt;Ans:&amp;nbsp; &amp;nbsp;2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;q2)how to create macro variable for&amp;nbsp;distinct values of zone&lt;/P&gt;&lt;P&gt;Ans:&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;zone1:&amp;nbsp; &amp;nbsp;SOUTH&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ZONE2: NORTH&lt;/P&gt;&lt;P&gt;i have tried below program for creationl of macro variables for zone ....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;select count(distinct(zone)) into:zone_count from test ;&lt;BR /&gt;select distinct(zone)into:zone1-:zone%left(&amp;amp;zone_count) from test;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;--------------------;&lt;/P&gt;&lt;P&gt;q3)how to create macro variable for distinct count of state with in zone&lt;/P&gt;&lt;P&gt;Ans:&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;SOUTH_state_1:&amp;nbsp; &amp;nbsp; AP&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SOUTH_state_2:&amp;nbsp; &amp;nbsp; TS&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;NORTH _state_1:&amp;nbsp; &amp;nbsp; MH&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;NORTH _state_2:&amp;nbsp; &amp;nbsp; GJ&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;NORTH _state_3&amp;nbsp; &amp;nbsp;&lt;SPAN&gt;&amp;nbsp; D&lt;/SPAN&gt;L&lt;/P&gt;&lt;P&gt;i have tried below program for creationl of macro variables for state with zone ....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro loop;&lt;BR /&gt;%do i=1 %to &amp;amp;zone_count ;&lt;BR /&gt;%global &amp;amp;&amp;amp;zone&amp;amp;i%left(1);&lt;BR /&gt;proc sql;&lt;BR /&gt;select STATE,count(distinct(state)) into:&amp;amp;&amp;amp;zone&amp;amp;i%left(1) from test&lt;BR /&gt;where zone="&amp;amp;&amp;amp;zone&amp;amp;i";&lt;BR /&gt;quit;&lt;BR /&gt;%end;&lt;BR /&gt;%mend;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but the above program is not working....&lt;/P&gt;&lt;P&gt;please help how to create separate macro&amp;nbsp; variables&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jul 2019 13:48:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-macro-variables/m-p/576587#M163261</guid>
      <dc:creator>thanikondharish</dc:creator>
      <dc:date>2019-07-25T13:48:26Z</dc:date>
    </item>
    <item>
      <title>Re: how to keep values with in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-macro-variables/m-p/576591#M163262</link>
      <description>&lt;P&gt;The phrase "keep values with in macro" does not have an obvious meaning to me.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The phrase "&lt;SPAN&gt;but the above program is not working...." requires a lot more information. What is not working? How do you know? Can you run the program again using OPTIONS MPRINT; as the first line, and then show us the LOG by pasting the log into the window that appears when you click on the {i} icon (do not paste the log directly into the reply window).&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jul 2019 13:52:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-macro-variables/m-p/576591#M163262</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-07-25T13:52:54Z</dc:date>
    </item>
    <item>
      <title>Re: how to keep values with in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-macro-variables/m-p/576593#M163263</link>
      <description>&lt;P&gt;What do you think the macro code you posted is doing?&lt;/P&gt;
&lt;P&gt;What output do you expect?&lt;/P&gt;
&lt;P&gt;Can you explain each step in the code?&lt;/P&gt;
&lt;P&gt;Remember to use the Insert Code or Insert SAS Code buttons in forum editor so format is preserved.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro loop;
%do i=1 %to &amp;amp;zone_count ;
  %global &amp;amp;&amp;amp;zone&amp;amp;i%left(1);
proc sql;
  select STATE,count(distinct(state)) into:&amp;amp;&amp;amp;zone&amp;amp;i%left(1) from test
  where zone="&amp;amp;&amp;amp;zone&amp;amp;i";
quit;
%end;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 25 Jul 2019 13:53:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-macro-variables/m-p/576593#M163263</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-07-25T13:53:53Z</dc:date>
    </item>
    <item>
      <title>Re: how to keep values with in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-macro-variables/m-p/576659#M163264</link>
      <description>&lt;P&gt;I merged the thread into yesterday's thread with the same question.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jul 2019 15:42:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-macro-variables/m-p/576659#M163264</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-07-25T15:42:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to create macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-macro-variables/m-p/576690#M163272</link>
      <description>&lt;P&gt;Start over from the questions and do this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) Show what you think the answer should be for each question if you just calculated the values manually.&lt;/P&gt;
&lt;P&gt;Please include details about how you are resolving the ambiguity in the questions to reach those answers.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) Then show how you attempted to generate those answers with code.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And indicate which ones either generated different answers than you expected or failed to generate any answer.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jul 2019 16:56:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-macro-variables/m-p/576690#M163272</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-07-25T16:56:01Z</dc:date>
    </item>
    <item>
      <title>Re: how to keep values with in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-macro-variables/m-p/576752#M163291</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/209685"&gt;@thanikondharish&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;If your input data set, though not sorted, is &lt;EM&gt;grouped&lt;/EM&gt; by (zone, state), as it appears to be in your data sample, there's no need to use SQL and reread it multiple times and/or use macros. Simply read it once and use BY processing with a nested DoW-loop:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test ;                                              
  input (zone state brnch) ($) sales ;                   
  cards ;                                                
SOUTH AP VZG 254                                         
SOUTH AP TRP 247                                         
SOUTH AP GUN 321                                         
SOUTH TS HYD 147                                         
SOUTH TS WGL 315                                         
NORTH MH MUM 254                                         
NORTH MH PUN 247                                         
NORTH GJ AHM 323                                         
NORTH DL NCR 148                                         
NORTH DL NOD 319                                         
run ;                                                    
                                                         
data _null_ ;                                            
  do qs = 1 by 1 until (last.zone) ;                     
    do until (last.state) ;                              
      set test ;                                         
      by zone state notsorted ;                          
    end ;                                                
    call symputx (catx ("_", zone, "state", qs), state) ;
  end ;                                                  
  call symputx (catx ("_", "zone", _n_), zone) ;         
run ;                                                    
                                                         
%put _user_ ;                                            
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The&amp;nbsp;%PUT statement reveals in the log:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;GLOBAL ZONE_2 NORTH
GLOBAL ZONE_1 SOUTH
GLOBAL NORTH_STATE_1 MH
GLOBAL NORTH_STATE_2 GJ
GLOBAL NORTH_STATE_3 DL
GLOBAL SOUTH_STATE_1 AP
GLOBAL SOUTH_STATE_2 TS
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If your real file is not grouped, sort it by (zone,state) beforehand.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jul 2019 21:36:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-macro-variables/m-p/576752#M163291</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-07-25T21:36:19Z</dc:date>
    </item>
    <item>
      <title>Re: how to keep values with in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-macro-variables/m-p/576774#M163305</link>
      <description>This is code is fine .But how to find How many macro variables are created&lt;BR /&gt;state wise.&lt;BR /&gt;</description>
      <pubDate>Fri, 26 Jul 2019 01:00:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-macro-variables/m-p/576774#M163305</guid>
      <dc:creator>thanikondharish</dc:creator>
      <dc:date>2019-07-26T01:00:43Z</dc:date>
    </item>
    <item>
      <title>Re: how to keep values with in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-macro-variables/m-p/576775#M163306</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/209685"&gt;@thanikondharish&lt;/a&gt;&amp;nbsp;:&lt;/P&gt;
&lt;P&gt;Not quite sure I understand your question. How this other macro variable you're talking about is supposed to be called? Which are the other macro variables whose count it should contain?&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jul 2019 01:11:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-macro-variables/m-p/576775#M163306</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-07-26T01:11:25Z</dc:date>
    </item>
    <item>
      <title>Re: how to keep values with in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-macro-variables/m-p/576776#M163307</link>
      <description>I need also how to keep distinct count values into macro variables&lt;BR /&gt;</description>
      <pubDate>Fri, 26 Jul 2019 01:13:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-macro-variables/m-p/576776#M163307</guid>
      <dc:creator>thanikondharish</dc:creator>
      <dc:date>2019-07-26T01:13:43Z</dc:date>
    </item>
    <item>
      <title>Re: how to keep values with in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-macro-variables/m-p/576781#M163311</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/209685"&gt;@thanikondharish&lt;/a&gt;&amp;nbsp;:&lt;/P&gt;
&lt;P&gt;Again, you're making me guess. The code can be easily adapted to get any distinct counts within the existing sorted order. Assuming that what you need is the distinct count of (zone) and (zone,state) key combos:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test ;                                              
  input (zone state brnch) ($) sales ;                   
  cards ;                                                
SOUTH AP VZG 254                                         
SOUTH AP TRP 247                                         
SOUTH AP GUN 321                                         
SOUTH TS HYD 147                                         
SOUTH TS WGL 315                                         
NORTH MH MUM 254                                         
NORTH MH PUN 247                                         
NORTH GJ AHM 323                                         
NORTH DL NCR 148                                         
NORTH DL NOD 319                                         
run ;                                                    
                                                         
data _null_ ;                                            
  do qs = 1 by 1 until (last.zone) ;                     
    do until (last.state) ;                              
      set test &lt;FONT color="#0000FF"&gt;end = lr&lt;/FONT&gt; ;                                
      by zone state notsorted ;                          
    end ;                                                
    call symputx (catx ("_", zone, "state", qs), state) ;
    &lt;FONT color="#0000FF"&gt;q + 1 ;&lt;/FONT&gt;                                              
  end ;                                                  
  call symputx (catx ("_", "zone", _n_), zone) ;         
  &lt;FONT color="#0000FF"&gt;if lr ;                                                
  call symputx (catx ("_", "zone_count"), _n_) ;         
  call symputx (catx ("_", "zone_state_count"), q) ;&lt;/FONT&gt;     
run ;                                                    
                                                         
%put _user_ ;                                            
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And in the log, you'll get:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;GLOBAL ZONE_COUNT 2
GLOBAL ZONE_2 NORTH
GLOBAL ZONE_1 SOUTH
GLOBAL NORTH_STATE_1 MH
GLOBAL NORTH_STATE_2 GJ
GLOBAL NORTH_STATE_3 DL
GLOBAL ZONE_STATE_COUNT 5
GLOBAL SOUTH_STATE_1 AP
GLOBAL SOUTH_STATE_2 TS
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jul 2019 02:12:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-macro-variables/m-p/576781#M163311</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-07-26T02:12:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to create macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-macro-variables/m-p/576813#M163329</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;q1)how to create macro variable for zone distinct count&lt;/P&gt;
&lt;P&gt;Ans:&amp;nbsp; &amp;nbsp;2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Check&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;q2)how to create macro variable for&amp;nbsp;distinct values of zone&lt;/P&gt;
&lt;P&gt;Ans:&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;zone1&lt;IMG class="emoticon emoticon-smileyfrustrated" src="https://communities.sas.com/i/smilies/16x16_smiley-frustrated.png" border="0" alt="Smiley Frustrated" title="Smiley Frustrated" /&gt;OUTH&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ZONE2:NORTH&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Check&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;q3)how to create macro variable for distinct count of state with in zone&lt;/P&gt;
&lt;P&gt;Ans:&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;SOUTH_state_1:&amp;nbsp; &amp;nbsp; AP&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SOUTH_state_2:&amp;nbsp; &amp;nbsp; TS&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;NORTH _state_1:&amp;nbsp; &amp;nbsp; MH&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;NORTH _state_2:&amp;nbsp; &amp;nbsp; GJ&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;NORTH _state_3&amp;nbsp; &amp;nbsp;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;IMG class="emoticon emoticon-smileyvery-happy" src="https://communities.sas.com/i/smilies/16x16_smiley-very-happy.png" border="0" alt="Smiley Very Happy" title="Smiley Very Happy" /&gt;L&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Unclear:&amp;nbsp; do you want count or values?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;q3)how to create macro variable for distinct count of branch with in zone and state&lt;/P&gt;
&lt;P&gt;Ans:&amp;nbsp; &amp;nbsp; &amp;nbsp; SOUTH_AP_branch1:&amp;nbsp; VZG&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SOUTH_AP_branch2:&amp;nbsp; &amp;nbsp;TRP&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;SOUTH_AP_branch3:&amp;nbsp; GUN&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SOUTH_state_TS_branch1:&amp;nbsp; &amp;nbsp;HYD&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SOUTH_state_TS_branch2:&amp;nbsp; &amp;nbsp;WGL&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Unclear:&amp;nbsp; do you want count or values?&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My "gut" says this is BAD...explain why you want to create these macro variables?&amp;nbsp; I bet storing in a data set would be a better approach.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyway, here you go.&amp;nbsp; Adjust if I misunderstood your unclear criteria:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* reset from previous runs ;
%global mvars;
proc sql noprint;
   select name into :mvars separated by " "
   from dictionary.macros
   where name like 'ZONE%' 
      or name like '%STATE%'
      or name like '%BRANCH%'
   order by name;
quit;

%symdel &amp;amp;mvars / nowarn;

data have;
input zone $ state$ branch$ sales;
cards;
SOUTH AP VZG 254
SOUTH AP TRP 247
SOUTH AP GUN 321
SOUTH TS HYD 147
SOUTH TS WGL 315
NORTH MH MUM 254
NORTH MH PUN 247
NORTH GJ AHM 323
NORTH DL NCR 148
NORTH DL NOD 319
;
run;

* sort ;
proc sort;
   by zone state branch;
run;

data _null_;
   set have end=eof;
   by zone state branch;
   if first.zone then do;
      zone_count+1;
      call symputx(catx("_","zone",zone_count),zone);
   end;
   if first.state then do;
      if first.zone then state_count=0;
      state_count+1;
      call symputx(catx("_",zone,"state",state_count),state);
   end;
   if first.branch then do;
      if first.zone or first.state then branch_count=0;
      branch_count+1;
      call symputx(catx("_",zone,state,"branch",branch_count),branch);
   end;
   if eof then call symputx("zone_count",zone_count);
run;

proc sql;
   select name, value
   from dictionary.macros
   where name like 'ZONE%' 
      or name like '%STATE%'
      or name like '%BRANCH%'
   order by name;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 26 Jul 2019 06:34:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-macro-variables/m-p/576813#M163329</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2019-07-26T06:34:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to create macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-macro-variables/m-p/576814#M163331</link>
      <description>&lt;P&gt;I was also playing with this, but naming your macro variables as you described is easier in a data step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* for debugging, print to output window ;
proc sql;
   * zone distinct count ;
   select count(0) as zone_count 
   from (select distinct zone from test);

   * zone distinct values ;
   select distinct zone as zone_value 
   from test;

   * distinct count of state within zone ;
   select zone, state, count(0) as zone_state_count 
   from (select distinct zone, state from test) group by zone;

   * distinct value of state within zone ;
   select distinct zone, state as zone_state_value 
   from test;

   * distinct count of branch within within zone + state ;
   select zone, state, branch, count(0) as zone_state_branch_count 
   from (select distinct zone, state, branch from test) group by zone, state;

   * distinct value of branch within within zone + state ;
   select distinct zone, state, branch as zone_state_branch_value 
   from test;
quit; 

* I don't think you need macro variables, but if you REALLY want them ;
proc sql;
   * zone distinct count ;
   select count(0) as zone_count into :zone_count trimmed
   from (select distinct zone from test);
   %put &amp;amp;=zone_count;

   * zone distinct values ;
   select distinct zone as zone_value into :zone1 - :zone9999
   from test;
   %put &amp;amp;=zone1;
   %put &amp;amp;=zone2;

   * distinct count of state within zone ;
   * skipping this one... ;
   select zone, state, count(0) as zone_state_count 
   from (select distinct zone, state from test) group by zone;

   * distinct value of state within zone ;
   select distinct zone, state as zone_state_value 
   from test;

   * distinct count of branch within within zone + state ;
   select zone, state, branch, count(0) as zone_state_branch_count 
   from (select distinct zone, state, branch from test) group by zone, state;

   * distinct value of branch within within zone + state ;
   select distinct zone, state, branch as zone_state_branch_value 
   from test;

   * at this point I gave up... ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 26 Jul 2019 06:36:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-macro-variables/m-p/576814#M163331</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2019-07-26T06:36:46Z</dc:date>
    </item>
  </channel>
</rss>

