<?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: SAS Macro select into function in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/SAS-Macro-select-into-function/m-p/758249#M80841</link>
    <description>&lt;P&gt;Thanks!&lt;/P&gt;</description>
    <pubDate>Thu, 29 Jul 2021 20:09:18 GMT</pubDate>
    <dc:creator>xliu1</dc:creator>
    <dc:date>2021-07-29T20:09:18Z</dc:date>
    <item>
      <title>SAS Macro select into function</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-Macro-select-into-function/m-p/758198#M80836</link>
      <description>&lt;P&gt;I am using macro function to select certain terms to use in the following programs, and use "%put" function to check whether I have selected correct terms. All I want to select is 201205 (i.e., 2nd row under TERM column) through 202101 (i.e., 28th row under TERM column). However, the output shows that terms selected are 201201-202008. How should I change the program to make correct selection? Here I attached a screen shot of the table I used. Thanks for any feedback!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="xliu1_0-1627580065004.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/62086iF2EB7D04D1406E5C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="xliu1_0-1627580065004.png" alt="xliu1_0-1627580065004.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL ; *noprint;
	SELECT	
		TERM
	INTO :Term2 - :Term28
	FROM TERM_REF;

%put &amp;amp;Term2-&amp;amp;Term28;

QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="xliu1_1-1627581461602.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/62093iD242E9A886E2D602/image-size/medium?v=v2&amp;amp;px=400" role="button" title="xliu1_1-1627581461602.png" alt="xliu1_1-1627581461602.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jul 2021 18:39:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-Macro-select-into-function/m-p/758198#M80836</guid>
      <dc:creator>xliu1</dc:creator>
      <dc:date>2021-07-29T18:39:55Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro select into function</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-Macro-select-into-function/m-p/758213#M80837</link>
      <description>&lt;P&gt;You can use _n_ to track the row numbers first. And then use proc sql.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
do term=201201 to 201230;
 output;
end;
run;

data keep1;
 set have;
 row=_n_;
run;

proc sql noprint;
select term into: term2 from keep1 where row=2;
select term into: term28 from keep1 where row=28;
quit;

%put &amp;amp;term2;
%put &amp;amp;term28;

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;If you have more rows then you can automate it using macros. But assuming you need only 2 rows, this is the simplest way.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jul 2021 19:01:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-Macro-select-into-function/m-p/758213#M80837</guid>
      <dc:creator>Rydhm</dc:creator>
      <dc:date>2021-07-29T19:01:30Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro select into function</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-Macro-select-into-function/m-p/758218#M80839</link>
      <description>&lt;P&gt;Depends on WHY you want to start with the second observation.&lt;/P&gt;
&lt;P&gt;Do you always want to skip the first observation?&amp;nbsp; Then just exclude it from the input to your SELECT statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;FROM TERM_REF(firstobs=2)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or do you want to limit by the values you mentioned instead?&amp;nbsp; Are those dates with format that only displays 6 digits?&amp;nbsp; Or are the numbers like 201,201?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where term_ref &amp;gt;= 201205&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jul 2021 19:04:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-Macro-select-into-function/m-p/758218#M80839</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-07-29T19:04:49Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro select into function</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-Macro-select-into-function/m-p/758231#M80840</link>
      <description>&lt;P&gt;If you prefer SQL, try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL ; *noprint;
	SELECT	
		TERM
	INTO :Term2 - :Term28
	FROM TERM_REF
	WHERE 201205 &amp;lt;= Term &amp;lt;= 202101
	;

%put &amp;amp;Term2-&amp;amp;Term28;

QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jul 2021 19:24:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-Macro-select-into-function/m-p/758231#M80840</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2021-07-29T19:24:31Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro select into function</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-Macro-select-into-function/m-p/758249#M80841</link>
      <description>&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jul 2021 20:09:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-Macro-select-into-function/m-p/758249#M80841</guid>
      <dc:creator>xliu1</dc:creator>
      <dc:date>2021-07-29T20:09:18Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro select into function</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-Macro-select-into-function/m-p/758251#M80842</link>
      <description>&lt;P&gt;You're welcome.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Incidentally, the code could be made more flexible like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET	Start			=	201205;
%LET	Stop			=	202101;

PROC SQL ; *noprint;
	SELECT	
		COUNT(TERM)	AS	Terms_Retreived
		INTO	:Terms_Retrieved	TRIMMED
		FROM TERM_REF
		WHERE &amp;amp;Start &amp;lt;= Term &amp;lt;= &amp;amp;Stop
		;
	SELECT	
		TERM
		INTO :Term1 -
		FROM TERM_REF
		WHERE &amp;amp;Start &amp;lt;= Term &amp;lt;= &amp;amp;Stop
		;
QUIT;

%IF	%BQUOTE(&amp;amp;Terms_Retrieved)	%THEN
	%DO;
		%put	NOTE:  &amp;amp;Term1-&amp;amp;&amp;amp;Term&amp;amp;Terms_Retrieved;
	%END;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;With the above code, you don't need to know in advance how many terms (or which terms) will be retrieved.&amp;nbsp; SAS will figure out how many terms are in the range you specify via the %LET statements, create the appropriate number of macro variables, and display the range in the log for you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jul 2021 20:12:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-Macro-select-into-function/m-p/758251#M80842</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2021-07-29T20:12:13Z</dc:date>
    </item>
  </channel>
</rss>

