<?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: How to Create a Vector in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-Create-a-Vector/m-p/132990#M27076</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Building on AYBiBTU's solution we can avoid the TRANSPOSE step by transposing in the DATA step, which becomes:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data use_array;&lt;/P&gt;&lt;P&gt;set foo;&lt;/P&gt;&lt;P&gt;by firmid year;&lt;/P&gt;&lt;P&gt;array seg[5] _temporary_;&amp;nbsp; /* make the dimension &amp;gt; largest number of segment id values */&lt;/P&gt;&lt;P&gt;if first.year then call missing(of seg{*});&lt;/P&gt;&lt;P&gt;seg{segmentid} = segmentsales;&lt;/P&gt;&lt;P&gt;if last.year then do i=1 to dim(seg);&lt;/P&gt;&lt;P&gt;&amp;nbsp; *something to array elements;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 13 Mar 2013 06:38:47 GMT</pubDate>
    <dc:creator>ArtC</dc:creator>
    <dc:date>2013-03-13T06:38:47Z</dc:date>
    <item>
      <title>How to Create a Vector</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Create-a-Vector/m-p/132988#M27074</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, all !&lt;BR /&gt;I have a large data set with the following variables:&lt;BR /&gt;Firmid (character)&amp;nbsp; year segmentID segmentsales siccode &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For each firmid year combination, I need to create a vector that contains its individual segment sales as well as sales of segments the firm does not have&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;BR /&gt;To do this, &lt;BR /&gt;1. first, I need to count the total number of distinct siccode&amp;nbsp; in the entire dataset, in the sample data given below, there are 7 unique siccode&lt;BR /&gt;2. my vector will have 7 elements, &lt;BR /&gt;e.g. for firmid=1000, year=1999, the vector (20,10,0,0,0,0,0), since the firm year, has only 2 segments with nonzero sales.&lt;BR /&gt;for firmid=1000, year=2000, the vector (15,12,13,0,0,0,0),&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;How do I program this? can I do this without proc iml ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Firmid year segmentID segmentsales siccode&lt;/P&gt;&lt;P&gt;1001 1999 1 20 4100&lt;/P&gt;&lt;P&gt;1001 1999 2 10 4200&lt;/P&gt;&lt;P&gt;1001 2000 1 15 4100&lt;/P&gt;&lt;P&gt;1001 2000 2 12 4200&lt;/P&gt;&lt;P&gt;1001 2000 3 13 5100&lt;/P&gt;&lt;P&gt;1002 1999 1 20 4100&lt;/P&gt;&lt;P&gt;1002 1999 2 13 9100&lt;/P&gt;&lt;P&gt;1002 2001 1 20 2867&lt;/P&gt;&lt;P&gt;1002 2001 2 13 3200&lt;/P&gt;&lt;P&gt;1002 2000 3 20 7100&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sincerely,&lt;/P&gt;&lt;P&gt;Lan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Mar 2013 20:27:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Create-a-Vector/m-p/132988#M27074</guid>
      <dc:creator>LanMin</dc:creator>
      <dc:date>2013-03-12T20:27:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to Create a Vector</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Create-a-Vector/m-p/132989#M27075</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Looks to me like you are trying to perform a transposition.&amp;nbsp; In the data step there is no concept of vector.&amp;nbsp; That data construct is left to IML.&amp;nbsp; You can use array's instead to probably reach whatever it is that your end goal entails.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data foo;&lt;/P&gt;&lt;P&gt; input firmid year segmentid segmentsales siccode;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;1001 1999 1 20 4100&lt;/P&gt;&lt;P&gt;1001 1999 2 10 4200&lt;/P&gt;&lt;P&gt;1001 2000 1 15 4100&lt;/P&gt;&lt;P&gt;1001 2000 2 12 4200&lt;/P&gt;&lt;P&gt;1001 2000 3 13 5100&lt;/P&gt;&lt;P&gt;1002 1999 1 20 4100&lt;/P&gt;&lt;P&gt;1002 1999 2 13 9100&lt;/P&gt;&lt;P&gt;1002 2001 1 20 2867&lt;/P&gt;&lt;P&gt;1002 2001 2 13 3200&lt;/P&gt;&lt;P&gt;1002 2000 3 20 7100&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort data=foo; by firmid year; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;options missing=0;&lt;/P&gt;&lt;P&gt;proc transpose data=foo out=bar(drop=_:) prefix=segmentid;&lt;/P&gt;&lt;P&gt; by firmid year;&lt;/P&gt;&lt;P&gt; var segmentsales;&lt;/P&gt;&lt;P&gt; id segmentid;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data use_array;&lt;/P&gt;&lt;P&gt; set bar;&lt;/P&gt;&lt;P&gt; array seg&lt;LI&gt; segmentid:;&lt;/LI&gt;&lt;/P&gt;&lt;P&gt; do i=1 to dim(seg);&lt;/P&gt;&lt;P&gt;&amp;nbsp; *something to array elements;&lt;/P&gt;&lt;P&gt; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Mar 2013 21:12:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Create-a-Vector/m-p/132989#M27075</guid>
      <dc:creator>AYBiBTU</dc:creator>
      <dc:date>2013-03-12T21:12:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to Create a Vector</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Create-a-Vector/m-p/132990#M27076</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Building on AYBiBTU's solution we can avoid the TRANSPOSE step by transposing in the DATA step, which becomes:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data use_array;&lt;/P&gt;&lt;P&gt;set foo;&lt;/P&gt;&lt;P&gt;by firmid year;&lt;/P&gt;&lt;P&gt;array seg[5] _temporary_;&amp;nbsp; /* make the dimension &amp;gt; largest number of segment id values */&lt;/P&gt;&lt;P&gt;if first.year then call missing(of seg{*});&lt;/P&gt;&lt;P&gt;seg{segmentid} = segmentsales;&lt;/P&gt;&lt;P&gt;if last.year then do i=1 to dim(seg);&lt;/P&gt;&lt;P&gt;&amp;nbsp; *something to array elements;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Mar 2013 06:38:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Create-a-Vector/m-p/132990#M27076</guid>
      <dc:creator>ArtC</dc:creator>
      <dc:date>2013-03-13T06:38:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to Create a Vector</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Create-a-Vector/m-p/132991#M27077</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you so much, Art and AYBIBTU.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Lan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Mar 2013 01:44:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Create-a-Vector/m-p/132991#M27077</guid>
      <dc:creator>LanMin</dc:creator>
      <dc:date>2013-03-15T01:44:05Z</dc:date>
    </item>
  </channel>
</rss>

