<?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: Assigning parameter values. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Assigning-parameter-values/m-p/77060#M16649</link>
    <description>OK, so you got me going on one of those little tours of the internet. I looke dinto %window and I think you need.&lt;BR /&gt;
&lt;BR /&gt;
*create the macro variable as a global;&lt;BR /&gt;
%global year;&lt;BR /&gt;
*a macro to get the user input;&lt;BR /&gt;
%macro get_year();&lt;BR /&gt;
*define the window;&lt;BR /&gt;
%window get_year columns=90 rows=15 irow=1 icolumn=1&lt;BR /&gt;
#2 @5 'Please enter the year required:' @45 year 4;&lt;BR /&gt;
*bring up the window and get input;&lt;BR /&gt;
%display get_year;&lt;BR /&gt;
%mend get_year;&lt;BR /&gt;
&lt;BR /&gt;
*call the macro;&lt;BR /&gt;
%get_year;&lt;BR /&gt;
&lt;BR /&gt;
*use the macro vairable created;&lt;BR /&gt;
data output_dataset;&lt;BR /&gt;
set input_dataset;&lt;BR /&gt;
where year=&amp;amp;year;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Even if this is not what you were after it has provided me with a little more knowledge. Thanks.</description>
    <pubDate>Tue, 17 Mar 2009 11:40:31 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2009-03-17T11:40:31Z</dc:date>
    <item>
      <title>Assigning parameter values.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assigning-parameter-values/m-p/77055#M16644</link>
      <description>I have hundred thousands of records in my data table with data from 1990 an onwards.&lt;BR /&gt;
&lt;BR /&gt;
After each year I want to run my code and get detailed statistics for that year, and some summary statistics for the 2 years before that year. I have code that produces these statistics. In that code I assign the year value to a variable in a data step.&lt;BR /&gt;
&lt;BR /&gt;
But I would like to pass the year value when the program starts running. I don't want to be forced to change code text each new year.&lt;BR /&gt;
&lt;BR /&gt;
In any "ordinary" programming language that would be easy.&lt;BR /&gt;
&lt;BR /&gt;
How can that be made with SAS code?&lt;BR /&gt;
&lt;BR /&gt;
/Anne</description>
      <pubDate>Tue, 17 Mar 2009 07:38:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assigning-parameter-values/m-p/77055#M16644</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-17T07:38:20Z</dc:date>
    </item>
    <item>
      <title>Re: Assigning parameter values.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assigning-parameter-values/m-p/77056#M16645</link>
      <description>SAS macro language. Quite a large subject to cover on a forum post but very basically, to get what you seem to want you would put a %let statement for your parameter and replace the hard coded year value with an &amp;amp;macrovariable. So for example:&lt;BR /&gt;
&lt;BR /&gt;
At the top of the program:&lt;BR /&gt;
&lt;BR /&gt;
%let year=1995;&lt;BR /&gt;
&lt;BR /&gt;
And in your datastep:&lt;BR /&gt;
&lt;BR /&gt;
data output;&lt;BR /&gt;
set input;&lt;BR /&gt;
where year=&amp;amp;year.;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
If your year value in your data is character then surround the resolution with double quotes e.g. where year="&amp;amp;year."; I could go on but macro language is a whole new subject to learn. These are the basics and hopefully gives you what you are looking for.&lt;BR /&gt;
&lt;BR /&gt;
Cheers&lt;BR /&gt;
Peter</description>
      <pubDate>Tue, 17 Mar 2009 09:26:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assigning-parameter-values/m-p/77056#M16645</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-17T09:26:20Z</dc:date>
    </item>
    <item>
      <title>Re: Assigning parameter values.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assigning-parameter-values/m-p/77057#M16646</link>
      <description>So it's necessary to change code each year, although only one line.&lt;BR /&gt;
&lt;BR /&gt;
There's nothing like an input box that you can launch with SAS code and pass the year value with?&lt;BR /&gt;
&lt;BR /&gt;
/Anne</description>
      <pubDate>Tue, 17 Mar 2009 10:37:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assigning-parameter-values/m-p/77057#M16646</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-17T10:37:29Z</dc:date>
    </item>
    <item>
      <title>Re: Assigning parameter values.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assigning-parameter-values/m-p/77058#M16647</link>
      <description>Hi Anne,&lt;BR /&gt;
&lt;BR /&gt;
You could make the program dynamic. If the program runs the data for the year previous to the current year, you can code that so that SAS can figure out what the year was by using the system date. I'm not sure that is what you are after though. &lt;BR /&gt;
&lt;BR /&gt;
There are ways to get user input from a window using the %window statement but it's pretty complicated. Feel free to look it up if you think it could save you time.&lt;BR /&gt;
&lt;BR /&gt;
Cheers&lt;BR /&gt;
Peter

Message was edited by: pznew</description>
      <pubDate>Tue, 17 Mar 2009 11:09:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assigning-parameter-values/m-p/77058#M16647</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-17T11:09:03Z</dc:date>
    </item>
    <item>
      <title>Re: Assigning parameter values.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assigning-parameter-values/m-p/77059#M16648</link>
      <description>When you invoke SAS, you can enter SYSPARM as an OPTION e.g. SYSPARM=’1995’. (The precise details how to do this will depend on your platform.) This is then available as a macro variable &amp;amp;SYSPARM.&lt;BR /&gt;
&lt;BR /&gt;
In my own code, I have a macro to analyse SYSPARM because a complex program may have several parameters to check, e.g. SYSPARM=’YEAR=1995'. However, this involves functions like %INDEX and %SUBSTR, which would not be required for basic code.</description>
      <pubDate>Tue, 17 Mar 2009 11:13:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assigning-parameter-values/m-p/77059#M16648</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-17T11:13:34Z</dc:date>
    </item>
    <item>
      <title>Re: Assigning parameter values.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assigning-parameter-values/m-p/77060#M16649</link>
      <description>OK, so you got me going on one of those little tours of the internet. I looke dinto %window and I think you need.&lt;BR /&gt;
&lt;BR /&gt;
*create the macro variable as a global;&lt;BR /&gt;
%global year;&lt;BR /&gt;
*a macro to get the user input;&lt;BR /&gt;
%macro get_year();&lt;BR /&gt;
*define the window;&lt;BR /&gt;
%window get_year columns=90 rows=15 irow=1 icolumn=1&lt;BR /&gt;
#2 @5 'Please enter the year required:' @45 year 4;&lt;BR /&gt;
*bring up the window and get input;&lt;BR /&gt;
%display get_year;&lt;BR /&gt;
%mend get_year;&lt;BR /&gt;
&lt;BR /&gt;
*call the macro;&lt;BR /&gt;
%get_year;&lt;BR /&gt;
&lt;BR /&gt;
*use the macro vairable created;&lt;BR /&gt;
data output_dataset;&lt;BR /&gt;
set input_dataset;&lt;BR /&gt;
where year=&amp;amp;year;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Even if this is not what you were after it has provided me with a little more knowledge. Thanks.</description>
      <pubDate>Tue, 17 Mar 2009 11:40:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assigning-parameter-values/m-p/77060#M16649</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-17T11:40:31Z</dc:date>
    </item>
    <item>
      <title>Re: Assigning parameter values.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assigning-parameter-values/m-p/77061#M16650</link>
      <description>Another method is to create an external file, (spreadsheet or text), containing the years to run.  Read the file in and loop over observations in the resulting dataset running analysis for each one. &lt;BR /&gt;
&lt;BR /&gt;
There are many ways to accomplish this in SAS.  You just need to find the one that fits the environment you are working in.</description>
      <pubDate>Tue, 17 Mar 2009 12:39:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assigning-parameter-values/m-p/77061#M16650</guid>
      <dc:creator>Flip</dc:creator>
      <dc:date>2009-03-17T12:39:57Z</dc:date>
    </item>
    <item>
      <title>Re: Assigning parameter values.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assigning-parameter-values/m-p/77062#M16651</link>
      <description>Anne: You can create a data set at the start of the program that will create a macro variable that lists the year for 2 years ago.&lt;BR /&gt;
&lt;BR /&gt;
data _null_;&lt;BR /&gt;
  analysis_date=today();&lt;BR /&gt;
  previous2_year_date=intnx('year',analysis_date,-2);&lt;BR /&gt;
  call symputx('year_start',year(previous2_year_date));&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
If this were run today:&lt;BR /&gt;
  analysis_date=March 19, 2009&lt;BR /&gt;
  previous2_year_date = January 1, 2007&lt;BR /&gt;
  macro variable &amp;amp;year_start resolves to 2007&lt;BR /&gt;
The macro variable will automatically change every year.</description>
      <pubDate>Thu, 19 Mar 2009 23:44:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assigning-parameter-values/m-p/77062#M16651</guid>
      <dc:creator>barheat</dc:creator>
      <dc:date>2009-03-19T23:44:41Z</dc:date>
    </item>
  </channel>
</rss>

