<?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 Filling variable with names of other variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Filling-variable-with-names-of-other-variables/m-p/228139#M267913</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset at the person level, with an ID variable and several month/year variables.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID &amp;nbsp; &amp;nbsp;200101 200102 &amp;nbsp;200103............through 201505&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; . &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; . &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Values of the month/year variables can either be 1 or missing.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I need is to create a new variable that tells me the date at which someone had their first value of 1. So for ID 1, that would be 200101, for 2, it would be 200103, etc.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm hoping for a solution that doesn't involve typing out everything by hand as I have over 100 month/year variables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
    <pubDate>Thu, 01 Oct 2015 21:38:23 GMT</pubDate>
    <dc:creator>Walternate</dc:creator>
    <dc:date>2015-10-01T21:38:23Z</dc:date>
    <item>
      <title>Filling variable with names of other variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-variable-with-names-of-other-variables/m-p/228139#M267913</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset at the person level, with an ID variable and several month/year variables.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID &amp;nbsp; &amp;nbsp;200101 200102 &amp;nbsp;200103............through 201505&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; . &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; . &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Values of the month/year variables can either be 1 or missing.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I need is to create a new variable that tells me the date at which someone had their first value of 1. So for ID 1, that would be 200101, for 2, it would be 200103, etc.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm hoping for a solution that doesn't involve typing out everything by hand as I have over 100 month/year variables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 01 Oct 2015 21:38:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-variable-with-names-of-other-variables/m-p/228139#M267913</guid>
      <dc:creator>Walternate</dc:creator>
      <dc:date>2015-10-01T21:38:23Z</dc:date>
    </item>
    <item>
      <title>Re: Filling variable with names of other variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-variable-with-names-of-other-variables/m-p/228144#M267914</link>
      <description>&lt;P&gt;Hi, made some assumptions as to how your data looks. &amp;nbsp;Solution also creates the variable as a real date. &amp;nbsp;If you don't care about that and just want the variable name, use the second data step.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;data x;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;input id d200101-d200103;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;datalines;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;1 1 . 1&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;2 . . 1&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;3 . 1 1&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;data y;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;format first1 yymon7.;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;set x;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;array d(*) d: ;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;first1&amp;nbsp;= input(substr(vname(d(whichn( 1,of d: ))),2,6),yymmn6.);&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;Obs&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; date&amp;nbsp;&amp;nbsp;&amp;nbsp; id&amp;nbsp;&amp;nbsp;&amp;nbsp; d200101&amp;nbsp;&amp;nbsp;&amp;nbsp; d200102&amp;nbsp;&amp;nbsp;&amp;nbsp; d200103&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;&amp;nbsp;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2001JAN&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;&amp;nbsp;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2001MAR&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;&amp;nbsp;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2001FEB&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Alternative, FIRST1 as a character variable (variable&amp;nbsp;name with the first&amp;nbsp;occurrence of a 1) ...&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data y;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;set x;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;array d(*) d: ;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;first1&amp;nbsp;= vname(d(whichn( 1,of d: )));&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Oct 2015 14:27:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-variable-with-names-of-other-variables/m-p/228144#M267914</guid>
      <dc:creator>MikeZdeb</dc:creator>
      <dc:date>2015-10-02T14:27:47Z</dc:date>
    </item>
    <item>
      <title>Re: Filling variable with names of other variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-variable-with-names-of-other-variables/m-p/228159#M267915</link>
      <description>&lt;P&gt;data have;&lt;BR /&gt;input id d200101-d200103;&lt;BR /&gt;datalines;&lt;BR /&gt;1 1 . 1&lt;BR /&gt;2 . . 1&lt;BR /&gt;3 . 1 1&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;array a{*} d200101-d200103;&lt;BR /&gt; do _n_=1 to dim(a);&lt;BR /&gt; if a{_n_}=1 then do;&lt;BR /&gt; date_first=vname(a{_n_});&lt;BR /&gt; leave;&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc print;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Oct 2015 02:51:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-variable-with-names-of-other-variables/m-p/228159#M267915</guid>
      <dc:creator>stat_sas</dc:creator>
      <dc:date>2015-10-02T02:51:49Z</dc:date>
    </item>
    <item>
      <title>Re: Filling variable with names of other variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-variable-with-names-of-other-variables/m-p/228174#M267916</link>
      <description>&lt;P&gt;As I always comment on these types of things, it is not a good idea to have data in your header row. &amp;nbsp;The name of a variable is an identifier and not data. &amp;nbsp;At worst, I would recommend changing the columns headers to have the same prefex and a suffix incrementor:&lt;/P&gt;
&lt;P&gt;VAR1, VAR2&lt;/P&gt;
&lt;P&gt;This way you can use VAR:, for example. &amp;nbsp;Far simpler coding. &amp;nbsp;However as you have data in your column names then I would suggest you normlise your data&amp;amp;colon;&lt;/P&gt;
&lt;P&gt;ID &amp;nbsp; &amp;nbsp; &amp;nbsp;YEAR &amp;nbsp; &amp;nbsp; &amp;nbsp;RESULT&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2012 &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2013 &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This will make your life far easier, for instnace your question on how to find the first 1 record:&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; select ID,min(YEAR) as MIN_YEAR&lt;/P&gt;
&lt;P&gt;&amp;nbsp; from HAVE&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; group by ID&lt;/P&gt;
&lt;P&gt;&amp;nbsp; having RESULT=1;&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You see the data is there to be processed on.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Oct 2015 08:17:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-variable-with-names-of-other-variables/m-p/228174#M267916</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-10-02T08:17:11Z</dc:date>
    </item>
    <item>
      <title>Re: Filling variable with names of other variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-variable-with-names-of-other-variables/m-p/228215#M267917</link>
      <description>&lt;P&gt;Here's another solutions:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;input ID&amp;nbsp;&amp;nbsp;&amp;nbsp; '200101'n '200102'n&amp;nbsp; '200103'n;&lt;BR /&gt;cards;&lt;BR /&gt;1 1 . 1&lt;BR /&gt;2 . . 1&lt;BR /&gt;3 . 1 1&lt;BR /&gt;;&lt;BR /&gt;&lt;BR /&gt;proc transpose data=have out=tran(rename=_NAME_ = DATE);by id;&lt;BR /&gt;&lt;BR /&gt;proc sort data=tran;by id descending col1 date;&lt;BR /&gt;&lt;BR /&gt;data prep;&lt;BR /&gt;set tran;&lt;BR /&gt;by id descending col1 date;&lt;BR /&gt;if first.id then first = date;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table want as&lt;BR /&gt;select distinct a.*, b.First&lt;BR /&gt;from have a left join&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; prep b on&lt;BR /&gt;a.id = b.id&lt;BR /&gt;where not missing(b.first)&lt;BR /&gt;order by id;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Oct 2015 14:19:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-variable-with-names-of-other-variables/m-p/228215#M267917</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2015-10-02T14:19:29Z</dc:date>
    </item>
  </channel>
</rss>

