<?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: Array and Column Names in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Array-and-Column-Names/m-p/530995#M145246</link>
    <description>Thanks!</description>
    <pubDate>Tue, 29 Jan 2019 14:48:55 GMT</pubDate>
    <dc:creator>sophia_SAS</dc:creator>
    <dc:date>2019-01-29T14:48:55Z</dc:date>
    <item>
      <title>Array and Column Names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-and-Column-Names/m-p/530969#M145232</link>
      <description>&lt;P&gt;Dear SAS community-&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to create new columns based on existing values in the original columns.&amp;nbsp; I have the part of the code figured out where I can create new column names based on the original columns using a combination of arrays and the vname function. However, I cannot figure out how to specify that I only want the column name if there is a non-missing value in the original column.&amp;nbsp; "Have" is my starting dataset. "Want" is the dataset I would like.&amp;nbsp; Below those two is my current code.&amp;nbsp; Any suggestions?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;input SubID $ apple pear orange;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;AA 1 . 1&lt;/P&gt;&lt;P&gt;BB 1 2 8&lt;/P&gt;&lt;P&gt;CC 3 . .&lt;/P&gt;&lt;P&gt;DD . 4 3&lt;/P&gt;&lt;P&gt;;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;final dataset;&lt;/P&gt;&lt;P&gt;SubjectID fruit1 fruit2 fruit3&lt;/P&gt;&lt;P&gt;AA apple . orange&lt;/P&gt;&lt;P&gt;BB apple pear orange&lt;/P&gt;&lt;P&gt;CC apple . .&lt;/P&gt;&lt;P&gt;DD . pear orange&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;array new_fruit(3) $25 fruit1 - fruit3 ;&lt;BR /&gt;retain fruit1 - fruit3;&lt;BR /&gt;array old_fruit(3) apple pear orange ;&lt;/P&gt;&lt;P&gt;do i = 1 to 3;&lt;BR /&gt;if old_fruit(i) ^=. then do;&amp;nbsp; *This part is not right though I can't figure out how to revise;&lt;BR /&gt;new_fruit(i) = vname(old_fruit(i));&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;drop i ;&lt;BR /&gt;run ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jan 2019 13:54:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-and-Column-Names/m-p/530969#M145232</guid>
      <dc:creator>sophia_SAS</dc:creator>
      <dc:date>2019-01-29T13:54:05Z</dc:date>
    </item>
    <item>
      <title>Re: Array and Column Names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-and-Column-Names/m-p/530976#M145237</link>
      <description>&lt;P&gt;Remove the RETAIN statement and all should be well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your IF THEN statement works, but doesn't erase the retained value from the previous observation.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jan 2019 14:01:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-and-Column-Names/m-p/530976#M145237</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-01-29T14:01:10Z</dc:date>
    </item>
    <item>
      <title>Re: Array and Column Names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-and-Column-Names/m-p/530977#M145238</link>
      <description>&lt;P&gt;I don't understand.&amp;nbsp; A dataset is a rectangle so every observation has to include every variable.&amp;nbsp; But the value can be missing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Normally the easiest way to create variable names from data is to use PROC TRANSPOSE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=have out=step1;
  by subid;
run;

proc transpose data=step1 out=want(drop=_name_ _label_) prefix=fruit;
 where not missing(col1);
 by subid ;
 var _name_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;       Sub
Obs    ID     fruit1    fruit2    fruit3

 1     AA     apple     orange
 2     BB     apple     pear      orange
 3     CC     apple
 4     DD     pear      orange&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Jan 2019 14:04:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-and-Column-Names/m-p/530977#M145238</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-01-29T14:04:42Z</dc:date>
    </item>
    <item>
      <title>Re: Array and Column Names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-and-Column-Names/m-p/530995#M145246</link>
      <description>Thanks!</description>
      <pubDate>Tue, 29 Jan 2019 14:48:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-and-Column-Names/m-p/530995#M145246</guid>
      <dc:creator>sophia_SAS</dc:creator>
      <dc:date>2019-01-29T14:48:55Z</dc:date>
    </item>
  </channel>
</rss>

