<?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: global variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/global-variables/m-p/693526#M211485</link>
    <description>BTW if you're trying to group into groups, using PROC RANK would be another option. RANK assigns values to percentile groups. &lt;BR /&gt;&lt;BR /&gt;proc rank data=dsn out=ranked_dsn groups=20;&lt;BR /&gt;var amt;&lt;BR /&gt;ranks rank_amt;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;set ranked_dsn;&lt;BR /&gt;where rank_amt between 8 and 18; *numbers may need tweaking;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;To group into 5 percentiles, number of groups = 20, where 0 = 0 to 5th percentile, 1 = 6 -10th percentile, 19 = 95 to 100&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Thu, 22 Oct 2020 14:51:37 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2020-10-22T14:51:37Z</dc:date>
    <item>
      <title>global variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/global-variables/m-p/693519#M211479</link>
      <description>&lt;P&gt;I am new to SAS and need help with macros. How can I create global variables that are outputs of other functions? For example:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc univariate data=dsn;
	var AMT;
	output out=mypctl 
                pctlpre=P_ 
		pctlpts= 40, 95;
run;&lt;/PRE&gt;&lt;P&gt;After I obtain the two values, I want use them for filtering:&lt;/P&gt;&lt;PRE&gt;data dsn;
	set dsn;
	where 60 &amp;lt; AMT &amp;lt; 7900 
		and DT &amp;lt;= '30Nov2018'd;
run;&lt;/PRE&gt;&lt;P&gt;I would like to avoid hard coding the values and set them as variables instead. The same applies to the date filter. The hard coded date was obtained as (the maximum date minus 1 year) after I looked up what the maximum date was. I could do this in R by setting something like&lt;/P&gt;&lt;P&gt;UL &amp;lt;- mypctl[1,2]&lt;/P&gt;&lt;P&gt;LL &amp;lt;- mypctl[1,1]&lt;/P&gt;&lt;P&gt;UL_DT &amp;lt;- max(DT) - years(1)&lt;/P&gt;&lt;P&gt;and use them in the data step for filtering. How can I do this in SAS? Even better if I can set those percentiles and the years to substract in the beginning of the program. Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 22 Oct 2020 14:27:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/global-variables/m-p/693519#M211479</guid>
      <dc:creator>asasha</dc:creator>
      <dc:date>2020-10-22T14:27:26Z</dc:date>
    </item>
    <item>
      <title>Re: global variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/global-variables/m-p/693523#M211482</link>
      <description>&lt;P&gt;Merging in data is usually easier than creating global variables.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/statgeek/SAS-Tutorials/blob/master/add_average_value_to_dataset.sas" target="_blank"&gt;https://github.com/statgeek/SAS-Tutorials/blob/master/add_average_value_to_dataset.sas&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Global variables would be macro variables.&lt;/P&gt;
&lt;P&gt;UCLA introductory tutorial on macro variables and macros&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/seminars/sas-macros-introduction/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/seminars/sas-macros-introduction/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Examples of common macro usage&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/SAS-9-4-Macro-Language-Reference-Has-a-New-Appendix/ta-p/291716" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/SAS-9-4-Macro-Language-Reference-Has-a-New-Appendix/ta-p/291716&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/338636"&gt;@asasha&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am new to SAS and need help with macros. How can I create global variables that are outputs of other functions? For example:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc univariate data=dsn;
	var AMT;
	output out=mypctl 
                pctlpre=P_ 
		pctlpts= 40, 95;
run;&lt;/PRE&gt;
&lt;P&gt;After I obtain the two values, I want use them for filtering:&lt;/P&gt;
&lt;PRE&gt;data dsn;
	set dsn;
	where 60 &amp;lt; AMT &amp;lt; 7900 
		and DT &amp;lt;= '30Nov2018'd;
run;&lt;/PRE&gt;
&lt;P&gt;I would like to avoid hard coding the values and set them as variables instead. The same applies to the date filter. The hard coded date was obtained as (the maximum date minus 1 year) after I looked up what the maximum date was. I could do this in R by setting something like&lt;/P&gt;
&lt;P&gt;UL &amp;lt;- mypctl[1,2]&lt;/P&gt;
&lt;P&gt;LL &amp;lt;- mypctl[1,1]&lt;/P&gt;
&lt;P&gt;UL_DT &amp;lt;- max(DT) - years(1)&lt;/P&gt;
&lt;P&gt;and use them in the data step for filtering. How can I do this in SAS? Even better if I can set those percentiles and the years to substract in the beginning of the program. Thanks!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Oct 2020 14:35:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/global-variables/m-p/693523#M211482</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-10-22T14:35:14Z</dc:date>
    </item>
    <item>
      <title>Re: global variables -- NOT NEEDED</title>
      <link>https://communities.sas.com/t5/SAS-Programming/global-variables/m-p/693524#M211483</link>
      <description>&lt;P&gt;I agree with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;, you don't need macro variables here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dsn;
    if _n_=1 then set mypctl;
    set dsn;
    where p_40 &amp;lt; amt &amp;lt; p_95 and ...
run;
    &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Oct 2020 14:47:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/global-variables/m-p/693524#M211483</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-10-22T14:47:31Z</dc:date>
    </item>
    <item>
      <title>Re: global variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/global-variables/m-p/693526#M211485</link>
      <description>BTW if you're trying to group into groups, using PROC RANK would be another option. RANK assigns values to percentile groups. &lt;BR /&gt;&lt;BR /&gt;proc rank data=dsn out=ranked_dsn groups=20;&lt;BR /&gt;var amt;&lt;BR /&gt;ranks rank_amt;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;set ranked_dsn;&lt;BR /&gt;where rank_amt between 8 and 18; *numbers may need tweaking;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;To group into 5 percentiles, number of groups = 20, where 0 = 0 to 5th percentile, 1 = 6 -10th percentile, 19 = 95 to 100&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 22 Oct 2020 14:51:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/global-variables/m-p/693526#M211485</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-10-22T14:51:37Z</dc:date>
    </item>
    <item>
      <title>Re: global variables -- NOT NEEDED</title>
      <link>https://communities.sas.com/t5/SAS-Programming/global-variables/m-p/693531#M211487</link>
      <description>&lt;P&gt;Thank you! The latest date in the dataset (maximum) needs to be used to filter out the observations in the past year (keep the records up to one year prior). If the data goes up to 14feb2020 then I want the data up to 14feb2019. How can I do that automatically?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Oct 2020 15:07:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/global-variables/m-p/693531#M211487</guid>
      <dc:creator>asasha</dc:creator>
      <dc:date>2020-10-22T15:07:11Z</dc:date>
    </item>
    <item>
      <title>Re: global variables -- NOT NEEDED</title>
      <link>https://communities.sas.com/t5/SAS-Programming/global-variables/m-p/693541#M211493</link>
      <description>&lt;P&gt;Same way. Compute the maximum date using PROC MEANS or PROC UNIVARIATE and then include it into the data set via the same method (&lt;FONT face="courier new,courier"&gt;if _n_=1 then set ...&lt;/FONT&gt;) You would use the INTNX function to find the date one year earlier.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc means data=dsn noprint;
    var amt dt;
    output out=stats p40(amt)=p40 p95(amt)=p95 max(dt)=maxdt;
run;

data dsn1;
    if _n_=1 then set stats;
    set dsn;
    if p40&amp;lt;amt&amp;lt;p95 and dt&amp;lt;intnx('year',maxdt,-1,'s');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 22 Oct 2020 15:26:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/global-variables/m-p/693541#M211493</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-10-22T15:26:35Z</dc:date>
    </item>
    <item>
      <title>Re: global variables -- NOT NEEDED</title>
      <link>https://communities.sas.com/t5/SAS-Programming/global-variables/m-p/693545#M211495</link>
      <description>proc sql;&lt;BR /&gt;create table want as&lt;BR /&gt;select *&lt;BR /&gt;from ranked_dsn where rank_amt between 8 and 18 &lt;BR /&gt;having (dt between intnx('year', max(dt), 0, 'b') and max(dt)) or (dt between intnx('year', max(dt), -1, 'b') and intnx('year', max(dt), -1, 's'));&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;Make your comparisons relative - untested but hopefully gives you an idea.</description>
      <pubDate>Thu, 22 Oct 2020 15:36:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/global-variables/m-p/693545#M211495</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-10-22T15:36:46Z</dc:date>
    </item>
  </channel>
</rss>

