<?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 create a macro to create a variable based on value ranges of another variable? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-to-create-a-variable-based-on-value-ranges/m-p/721774#M223750</link>
    <description>&lt;P&gt;I don't see how macro-variables fit into solving your issue. The ranges you have defined are partially overlapping, so which value should be in snap for April, 20th? If you can get rid of the overlappings, a format is the best way to solve the problem. If you can't, then using&amp;nbsp; a select-statement in a data-step seems feasible.&lt;/P&gt;</description>
    <pubDate>Thu, 25 Feb 2021 08:01:52 GMT</pubDate>
    <dc:creator>andreas_lds</dc:creator>
    <dc:date>2021-02-25T08:01:52Z</dc:date>
    <item>
      <title>How to create a macro to create a variable based on value ranges of another variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-to-create-a-variable-based-on-value-ranges/m-p/721770#M223747</link>
      <description>&lt;P&gt;I have a data set with one field date, which is in date9. format:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Date&lt;/P&gt;
&lt;P&gt;01APR2020&lt;BR /&gt;02APR2020&lt;BR /&gt;04APR2020&lt;BR /&gt;05APR2020&lt;BR /&gt;06APR2020&lt;BR /&gt;21APR2020&lt;BR /&gt;22APR2020&lt;BR /&gt;23APR2020&lt;BR /&gt;25APR2020&lt;BR /&gt;26APR2020&lt;BR /&gt;27APR2020&lt;/P&gt;
&lt;P&gt;The values in Date field ranges from 01APR2020 to 31JUL2020.&lt;/P&gt;
&lt;P&gt;Now I want to create another variable called Snap which will have values based on different ranges of the Date variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;The value of snap will be as:&lt;/P&gt;
&lt;P&gt;Range of values of Date Variable&amp;nbsp; &amp;nbsp; &amp;nbsp; Snap will take value&lt;BR /&gt;01 Mar 2020 to 22 Apr 2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 30Apr2020&lt;BR /&gt;01 Apr 2020 to 23 May 2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;31May2020&lt;BR /&gt;01 May 2020 to 22 Jun 2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;30Jun2020&lt;BR /&gt;01 Jun 2020 to 23 Jul 2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 31Jul2020&lt;BR /&gt;01 Jul 2020 to 31 Jul 2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;31Aug2020&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How do I create a macro to achieve this? Thank you&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Feb 2021 07:32:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-to-create-a-variable-based-on-value-ranges/m-p/721770#M223747</guid>
      <dc:creator>Shradha1</dc:creator>
      <dc:date>2021-02-25T07:32:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a macro to create a variable based on value ranges of another variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-to-create-a-variable-based-on-value-ranges/m-p/721771#M223748</link>
      <description>&lt;P&gt;You don't need a macro but define a format to "translate" range into SNAP.&lt;/P&gt;
&lt;P&gt;BUT - what would be the snap for 10APR2020? - according to first range it should be 30Apr2020 while according to second range it needs be 31May2020 ???&lt;/P&gt;</description>
      <pubDate>Thu, 25 Feb 2021 07:51:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-to-create-a-variable-based-on-value-ranges/m-p/721771#M223748</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2021-02-25T07:51:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a macro to create a variable based on value ranges of another variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-to-create-a-variable-based-on-value-ranges/m-p/721774#M223750</link>
      <description>&lt;P&gt;I don't see how macro-variables fit into solving your issue. The ranges you have defined are partially overlapping, so which value should be in snap for April, 20th? If you can get rid of the overlappings, a format is the best way to solve the problem. If you can't, then using&amp;nbsp; a select-statement in a data-step seems feasible.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Feb 2021 08:01:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-to-create-a-variable-based-on-value-ranges/m-p/721774#M223750</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-02-25T08:01:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a macro to create a variable based on value ranges of another variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-to-create-a-variable-based-on-value-ranges/m-p/721780#M223753</link>
      <description>Yes the ranges will be overlapping</description>
      <pubDate>Thu, 25 Feb 2021 08:41:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-to-create-a-variable-based-on-value-ranges/m-p/721780#M223753</guid>
      <dc:creator>Shradha1</dc:creator>
      <dc:date>2021-02-25T08:41:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a macro to create a variable based on value ranges of another variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-to-create-a-variable-based-on-value-ranges/m-p/721781#M223754</link>
      <description>Yes some values will fall into two snaps. The ranges will be overlapping. So the entry for 10APR2020 will be duplicated, against one entry the value will be 30Apr2020 and 31may2020 against other. Similarly for other values</description>
      <pubDate>Thu, 25 Feb 2021 08:43:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-to-create-a-variable-based-on-value-ranges/m-p/721781#M223754</guid>
      <dc:creator>Shradha1</dc:creator>
      <dc:date>2021-02-25T08:43:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a macro to create a variable based on value ranges of another variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-to-create-a-variable-based-on-value-ranges/m-p/721793#M223757</link>
      <description>&lt;P&gt;To bad, but still a format can be used. Unfortunately i wasn't able to use a date-constant on the right side in the format-definition, could be a special feature of proc summary.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   input Date :date9.;

   format Date date9.;
   datalines;
01APR2020
02APR2020
04APR2020
05APR2020
06APR2020
21APR2020
22APR2020
23APR2020
25APR2020
26APR2020
27APR2020
;


data extended;
   set have;

   dummy = _n_;
   snap = date;
run;

proc format;
   value SnapFmt (multilabel notsorted)
      '01Mar2020'd - '22Apr2020'd = '30Apr2020'
      '01Apr2020'd - '23May2020'd = '31May2020'
      '01May2020'd - '22Jun2020'd = '30Jun2020'
      '01Jun2020'd - '23Jul2020'd = '31Jul2020'
      '01Jul2020'd - '31Jul2020'd = '31Aug2020'
   ;
run;

proc summary data=extended nway;
   class dummy snap / mlf order=data ;
   format snap SnapFmt.;
   id date;
   output out= NearlyWant(drop= _: dummy) ;
run;

data want;
   set NearlyWant(rename= (snap = snapStr));

   attrib snap length=8 format=date9.;

   snap= input(snapStr, date9.);

   drop snapStr;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 25 Feb 2021 09:21:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-to-create-a-variable-based-on-value-ranges/m-p/721793#M223757</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-02-25T09:21:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a macro to create a variable based on value ranges of another variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-to-create-a-variable-based-on-value-ranges/m-p/721794#M223758</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/361528"&gt;@Shradha1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Yes some values will fall into two snaps. The ranges will be overlapping. So the entry for 10APR2020 will be duplicated, against one entry the value will be 30Apr2020 and 31may2020 against other. Similarly for other values&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Use next coed:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
 set have;
     if date between '01Mar2020'd and '22Apr2020'd then do; snap='30Apr2020'd; output; end;
     if date between '01Apr2020'd and '23May2020'd then do; snap='31May2020'd; output; end;
     if date between '01May2020'd and '22Jun2020'd then do; snap='30Jun2020'd; output; end;
     if date between '01Jun2020'd and '23Jul2020'd then do; snap='31Jul2020'd; output; end;
     if date between '01Jul2020'd and '31Jul2020'd then do; snap='31Aug2020'd; output; end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thus you will get the wanted duplicates.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Feb 2021 09:43:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-to-create-a-variable-based-on-value-ranges/m-p/721794#M223758</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2021-02-25T09:43:07Z</dc:date>
    </item>
  </channel>
</rss>

