<?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 SAS Array Help in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-Array-Help/m-p/537255#M147717</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;		proc sql noprint;
			select max(EXCEPTION_CD)
			into :no_exc
			from REWARDS.REGISTRATION
			where not missing(EXCEPTION_CD)
			;
		quit;

		%let no_exc = &amp;amp;no_exc;

		%put no_exc: &amp;amp;no_exc;

		/* Get the unique exception codes and stored them in macro variables excx */
		proc sql noprint;
			select distinct EXCEPTION_CD 
			into :exc1-:exc&amp;amp;no_exc
			from REWARDS.REGISTRATION
			where not missing(EXCEPTION_CD)
			;
		quit;

		/* Loop through the number of exceptions and stored the candidate codes, candidate group codes and exception types associated to each exception code
		   in macro variables */
		%do i = 1 %to &amp;amp;no_exc;

			%global cnd_cd_exc&amp;amp;i cnd_grp_cd_exc&amp;amp;i exc_type&amp;amp;i;

			proc sql noprint;

				select distinct quote(CND_CD), quote(CND_GRP_CD), EXCEPTION_TYPE
				into :cnd_cd_exc&amp;amp;i separated by ',', :cnd_grp_cd_exc&amp;amp;i separated by ',', :exc_type&amp;amp;i
				from REWARDS.REGISTRATION
				where EXCEPTION_CD = "&amp;amp;&amp;amp;exc&amp;amp;i";
			quit;

			%put codes: &amp;amp;&amp;amp;cnd_cd_exc&amp;amp;i;
			%put grp_cd: &amp;amp;&amp;amp;cnd_grp_cd_exc&amp;amp;i;
			%put types: &amp;amp;&amp;amp;exc_type&amp;amp;i;

		%end;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried searching but am unable to get any results relevant to my issue.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I am trying to Achieve:&lt;/P&gt;&lt;P&gt;I have a csv file with Exception Codes ( 1-99), however, only 10 are being used currently (1-10). Each has an exception logic. For example:&lt;/P&gt;&lt;P&gt;Code 1 is for Sales, as in, they met Sales goal, if though they did not, so Sales Exception = Sales * Reward Dollar.&lt;/P&gt;&lt;P&gt;Code 2 is for Age, as in, they qualify for Senior Tier, Age Exception = Sales * Reward Dollar * Age Multiplier&lt;/P&gt;&lt;P&gt;Code 3 is for Disability, as in they qualify for Disable Tier = Sales * Reward Dollar * Disability Multiplier&lt;/P&gt;&lt;P&gt;Code 4 is for Region, as in they qualify for Region Tier = Sales * Reward Dollar * Region Multiplier&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the below code that generates the Array in a Macro, and it works great. However, that only stands true as long as all the 4 (1-4) Codes Exist or all 10 exist. Under the code, lets say, if Code 2 does not exist, it would put Code 3 under Code 2, and thus the calculation would be wrong. Same would happen with Code 4, which will now be Code 3.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All the below is done in a Macro Code, followed by utilization using "%if %symexist(cnd_cd_exc1) %THEN %DO;", and this statement follows the calculation logic. (This is the statement after the symexist: if CANDIDATE_CD in (&amp;amp;&amp;amp;cnd_cd_exc1) then do;)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I want from below is, Code 1 is always exc1 and Code 3 is always exc3, weather code 2 exist or does not exist.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do let me know if you need anything else.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please Note: The whole question is arbitrary, as specifics are obviously confidential. The example is just an example, and provides a way for my solution.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Specifics: SAS 9.3 on Unix. All runs are ni EG 5.1&lt;/P&gt;</description>
    <pubDate>Wed, 20 Feb 2019 23:45:44 GMT</pubDate>
    <dc:creator>rahulp</dc:creator>
    <dc:date>2019-02-20T23:45:44Z</dc:date>
    <item>
      <title>SAS Array Help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Array-Help/m-p/537255#M147717</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;		proc sql noprint;
			select max(EXCEPTION_CD)
			into :no_exc
			from REWARDS.REGISTRATION
			where not missing(EXCEPTION_CD)
			;
		quit;

		%let no_exc = &amp;amp;no_exc;

		%put no_exc: &amp;amp;no_exc;

		/* Get the unique exception codes and stored them in macro variables excx */
		proc sql noprint;
			select distinct EXCEPTION_CD 
			into :exc1-:exc&amp;amp;no_exc
			from REWARDS.REGISTRATION
			where not missing(EXCEPTION_CD)
			;
		quit;

		/* Loop through the number of exceptions and stored the candidate codes, candidate group codes and exception types associated to each exception code
		   in macro variables */
		%do i = 1 %to &amp;amp;no_exc;

			%global cnd_cd_exc&amp;amp;i cnd_grp_cd_exc&amp;amp;i exc_type&amp;amp;i;

			proc sql noprint;

				select distinct quote(CND_CD), quote(CND_GRP_CD), EXCEPTION_TYPE
				into :cnd_cd_exc&amp;amp;i separated by ',', :cnd_grp_cd_exc&amp;amp;i separated by ',', :exc_type&amp;amp;i
				from REWARDS.REGISTRATION
				where EXCEPTION_CD = "&amp;amp;&amp;amp;exc&amp;amp;i";
			quit;

			%put codes: &amp;amp;&amp;amp;cnd_cd_exc&amp;amp;i;
			%put grp_cd: &amp;amp;&amp;amp;cnd_grp_cd_exc&amp;amp;i;
			%put types: &amp;amp;&amp;amp;exc_type&amp;amp;i;

		%end;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried searching but am unable to get any results relevant to my issue.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I am trying to Achieve:&lt;/P&gt;&lt;P&gt;I have a csv file with Exception Codes ( 1-99), however, only 10 are being used currently (1-10). Each has an exception logic. For example:&lt;/P&gt;&lt;P&gt;Code 1 is for Sales, as in, they met Sales goal, if though they did not, so Sales Exception = Sales * Reward Dollar.&lt;/P&gt;&lt;P&gt;Code 2 is for Age, as in, they qualify for Senior Tier, Age Exception = Sales * Reward Dollar * Age Multiplier&lt;/P&gt;&lt;P&gt;Code 3 is for Disability, as in they qualify for Disable Tier = Sales * Reward Dollar * Disability Multiplier&lt;/P&gt;&lt;P&gt;Code 4 is for Region, as in they qualify for Region Tier = Sales * Reward Dollar * Region Multiplier&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the below code that generates the Array in a Macro, and it works great. However, that only stands true as long as all the 4 (1-4) Codes Exist or all 10 exist. Under the code, lets say, if Code 2 does not exist, it would put Code 3 under Code 2, and thus the calculation would be wrong. Same would happen with Code 4, which will now be Code 3.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All the below is done in a Macro Code, followed by utilization using "%if %symexist(cnd_cd_exc1) %THEN %DO;", and this statement follows the calculation logic. (This is the statement after the symexist: if CANDIDATE_CD in (&amp;amp;&amp;amp;cnd_cd_exc1) then do;)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I want from below is, Code 1 is always exc1 and Code 3 is always exc3, weather code 2 exist or does not exist.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do let me know if you need anything else.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please Note: The whole question is arbitrary, as specifics are obviously confidential. The example is just an example, and provides a way for my solution.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Specifics: SAS 9.3 on Unix. All runs are ni EG 5.1&lt;/P&gt;</description>
      <pubDate>Wed, 20 Feb 2019 23:45:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Array-Help/m-p/537255#M147717</guid>
      <dc:creator>rahulp</dc:creator>
      <dc:date>2019-02-20T23:45:44Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Array Help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Array-Help/m-p/537331#M147770</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you know you may miss some codes, why don't you check them and use placeholders to replace the missing ones?&lt;/P&gt;&lt;P&gt;I'd rather recommend using SAS datasets and proc transpose&amp;nbsp;instead of macro variables for data management activities&lt;/P&gt;&lt;P&gt;Provide some data if it doesn't work, showing the results you want to achieve.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Feb 2019 07:35:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Array-Help/m-p/537331#M147770</guid>
      <dc:creator>Oligolas</dc:creator>
      <dc:date>2019-02-21T07:35:57Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Array Help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Array-Help/m-p/537345#M147780</link>
      <description>&lt;P&gt;I think something lke this may work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Get the unique exception codes and store them in macro variable exceptions */
%local Exceptions Exception i;
proc sql noprint;
   select distinct EXCEPTION_CD
   into :exceptions separated by ' '
   from REWARDS.REGISTRATION
   where not missing(EXCEPTION_CD)
   order by 1
   ;
quit;


%put Exceptions in file: &amp;amp;exceptions;

/* Delete macro symbols from previous run, if any, there can be up to 99 exception codes */
%do i=1 %to 99;
  %if %symexist(cnd_cd_exc&amp;amp;i) %then
    %symdel cnd_cd_exc&amp;amp;i;
  %if %symexist(cnd_grp_cd_exc&amp;amp;i) %then
    %symdel cnd_grp_cd_exc&amp;amp;i;
  %if %symexist(exc_type&amp;amp;i) %then
    %symdel exc_type&amp;amp;i;
  %end;

/* Loop through the number of exceptions and stored the candidate codes, candidate group codes and exception types associated to each exception code
           in macro variables */
%do i = 1 %to &amp;amp;sqlobs;
   %let exception=%scan(&amp;amp;exceptions,&amp;amp;i);
   %global cnd_cd_exc&amp;amp;exception cnd_grp_cd_exc&amp;amp;exception exc_type&amp;amp;exception;
   proc sql noprint;
     select distinct quote(CND_CD), quote(CND_GRP_CD), EXCEPTION_TYPE
     into :cnd_cd_exc&amp;amp;exception separated by ',', :cnd_grp_cd_exc&amp;amp;exception separated by ',', :exc_type&amp;amp;exception
     from REWARDS.REGISTRATION
     where EXCEPTION_CD = "&amp;amp;exception";
     quit;
   %put codes: &amp;amp;&amp;amp;cnd_cd_exc&amp;amp;exception;
   %put grp_cd: &amp;amp;&amp;amp;cnd_grp_cd_exc&amp;amp;exception;
   %put types: &amp;amp;&amp;amp;exc_type&amp;amp;exception;
   %end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I put in a step to delete previous values, in case you run the code more than once in the same session.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Feb 2019 09:14:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Array-Help/m-p/537345#M147780</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2019-02-21T09:14:08Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Array Help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Array-Help/m-p/537406#M147807</link>
      <description>&lt;P&gt;This is perfect. Applied the logic you presented and it worked like a charm.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Major and much thanks for the solution&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76464"&gt;@s_lassen&lt;/a&gt;&amp;nbsp;, without your help, my project would have been against the wall and would have required major modifications and time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Feb 2019 14:33:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Array-Help/m-p/537406#M147807</guid>
      <dc:creator>rahulp</dc:creator>
      <dc:date>2019-02-21T14:33:39Z</dc:date>
    </item>
  </channel>
</rss>

