<?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 how to convert multiple columns to single column in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-convert-multiple-columns-to-single-column/m-p/4034#M1273</link>
    <description>I have a Oracle library in my SMC where i have a table supplier in which i have column sundry_code which occurs 10 since in oracle it is written in&lt;BR /&gt;
sundry_code * 10&lt;BR /&gt;
bcoz of that when i open this table in EG i get 10 columns for 1 row.&lt;BR /&gt;
sundry_code_001,sundry_code_002,...sundry_code_010.&lt;BR /&gt;
Now i want to convert these 10 columns back to 1 column.&lt;BR /&gt;
In this also i have one more column sundry_val which occurs for 10 times.&lt;BR /&gt;
So how should i go ahead doing in EG to get only two columns like sundry_code and sundry_val</description>
    <pubDate>Fri, 03 Aug 2007 09:27:04 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2007-08-03T09:27:04Z</dc:date>
    <item>
      <title>how to convert multiple columns to single column</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-convert-multiple-columns-to-single-column/m-p/4034#M1273</link>
      <description>I have a Oracle library in my SMC where i have a table supplier in which i have column sundry_code which occurs 10 since in oracle it is written in&lt;BR /&gt;
sundry_code * 10&lt;BR /&gt;
bcoz of that when i open this table in EG i get 10 columns for 1 row.&lt;BR /&gt;
sundry_code_001,sundry_code_002,...sundry_code_010.&lt;BR /&gt;
Now i want to convert these 10 columns back to 1 column.&lt;BR /&gt;
In this also i have one more column sundry_val which occurs for 10 times.&lt;BR /&gt;
So how should i go ahead doing in EG to get only two columns like sundry_code and sundry_val</description>
      <pubDate>Fri, 03 Aug 2007 09:27:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-convert-multiple-columns-to-single-column/m-p/4034#M1273</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2007-08-03T09:27:04Z</dc:date>
    </item>
    <item>
      <title>Re: how to convert multiple columns to single column</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-convert-multiple-columns-to-single-column/m-p/4035#M1274</link>
      <description>Hi:&lt;BR /&gt;
  Is this what you mean? You have data that looks like this (I only typed 3 instead of 10):&lt;BR /&gt;
[pre]&lt;BR /&gt;
What does the data look like&lt;BR /&gt;
&lt;BR /&gt;
        sundry_     sundry_     sundry_     sundry_    sundry_    sundry_&lt;BR /&gt;
name    code_001    code_002    code_003    val_001    val_002    val_003&lt;BR /&gt;
&lt;BR /&gt;
alan      aaa         bbb         ccc         100        200        300&lt;BR /&gt;
bob       aaa         ccc         fff         111        333        777&lt;BR /&gt;
&lt;BR /&gt;
[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
And, your data probably has more columns or variables, but what you WANT falls into 2 possibilities in my mind. &lt;BR /&gt;
[pre]&lt;BR /&gt;
Possibility 1: One Row for each sundry_code&lt;BR /&gt;
name    sundry_code        sundry_val&lt;BR /&gt;
&lt;BR /&gt;
alan          aaa               100&lt;BR /&gt;
alan          bbb               200&lt;BR /&gt;
alan          ccc               300&lt;BR /&gt;
bob           aaa               111&lt;BR /&gt;
bob           ccc               333&lt;BR /&gt;
bob           fff               777&lt;BR /&gt;
[/pre]&lt;BR /&gt;
or you want to "collapse" the information like this&lt;BR /&gt;
[pre]&lt;BR /&gt;
Possibility 2: Collapse all the codes and values together&lt;BR /&gt;
                       &lt;BR /&gt;
name    sundry_code     sundry_val&lt;BR /&gt;
alan    aaa bbb ccc        600&lt;BR /&gt;
bob     aaa ccc fff       1221&lt;BR /&gt;
[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
The technique you use will depend on what your input data looks like and what your desired output data should look like. For Possibility 1, you would have to treat the numbered codes and values as an array and then you'd "unarray" the values, creating a separate row for every array member. For Possibility 2, you would have to concatenate all the separate codes together and then sum up all the separate values.&lt;BR /&gt;
 &lt;BR /&gt;
In order to achieve Possibility 1, you'd have to use a DATA step program and the ARRAY statement and if you are not familiar with these techniques, then Tech Support might be your best bet for help with this task. In order to achieve Possibility 2, you could use either a PROC SQL query, such as the kind you build with EG or you could use a DATA step program. Again, Tech Support can help you figure out the best way to accomplish what you need to do.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Fri, 03 Aug 2007 17:26:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-convert-multiple-columns-to-single-column/m-p/4035#M1274</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2007-08-03T17:26:47Z</dc:date>
    </item>
    <item>
      <title>Re: how to convert multiple columns to single column</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-convert-multiple-columns-to-single-column/m-p/4036#M1275</link>
      <description>thanx ya my case possibilty1.Is there any task in EG which i can use directly to get that output</description>
      <pubDate>Mon, 06 Aug 2007 13:47:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-convert-multiple-columns-to-single-column/m-p/4036#M1275</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2007-08-06T13:47:33Z</dc:date>
    </item>
    <item>
      <title>Re: how to convert multiple columns to single column</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-convert-multiple-columns-to-single-column/m-p/4037#M1276</link>
      <description>Hi,&lt;BR /&gt;
 I don't know of any task that would do it directly. I suppose you could build multiple queries using the query task:&lt;BR /&gt;
[pre]&lt;BR /&gt;
proc sql;&lt;BR /&gt;
  create table hold1 as&lt;BR /&gt;
    select name, &lt;BR /&gt;
              sundry_code_001 as sundry_code,&lt;BR /&gt;
              sundry_val_001 as sundry_val&lt;BR /&gt;
    from lib.file;&lt;BR /&gt;
quit;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
  &lt;BR /&gt;
 And then you'd end up with 10 "work" files that you'd have to concatenate back together.&lt;BR /&gt;
  &lt;BR /&gt;
  Or, you could open up a code node in EG and use a DATA Step program to build your output file with one pass through the data. For example, to actually make the output that I showed as Possibility 1, I made a work file called work.testit with just 3 numbered sundry codes and then this program "unarrayed" the variables and created one row for each name:&lt;BR /&gt;
[pre]&lt;BR /&gt;
  data Poss1(keep=name sundry_code sundry_val);&lt;BR /&gt;
      set work.testit;&lt;BR /&gt;
      array sc $ sundry_code_001 - sundry_code_003;&lt;BR /&gt;
      array sv sundry_val_001 - sundry_val_003;&lt;BR /&gt;
      do i = 1 to 3 by 1;&lt;BR /&gt;
          sundry_code = sc(i);&lt;BR /&gt;
          sundry_val = sv(i);&lt;BR /&gt;
          output;&lt;BR /&gt;
      end;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
The result of this program is a dataset, WORK.POSS1 that contains the data as shown for Possibility 1 choice above. The DATA step has the ability to use the ARRAY statement to treat your "numbered" variables as though they are array members. So there's an ARRAY statement for sundry_code_001 - sundry_code_003 (a character $ array) and another ARRAY statement for sundry_val_001 - sundry_val_003 (a numeric array). Then, the DO loop creates the new variables sundry_code and sundry_val from the array members (using the sc(i) and sv(i) reference method). Finally, the OUTPUT statement outputs one row for every iteration through the loop. The KEEP option guarantees that the final dataset contains only the columns I want to keep in the final dataset.&lt;BR /&gt;
  &lt;BR /&gt;
For a production program, I would recommend a few more changes to guarantee that you did not output any rows if both sundry_code or sundry_val were missing. And perhaps add any format or label statements that would make the data more meaningful when it was used.&lt;BR /&gt;
 &lt;BR /&gt;
For more help with figuring out how to do this in EG, your best bet is to contact Tech Support.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Mon, 06 Aug 2007 15:42:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-convert-multiple-columns-to-single-column/m-p/4037#M1276</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2007-08-06T15:42:38Z</dc:date>
    </item>
    <item>
      <title>Re: how to convert multiple columns to single column</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-convert-multiple-columns-to-single-column/m-p/4038#M1277</link>
      <description>thanx,&lt;BR /&gt;
I got one task in EG which is stack but at a time it converts that 10 columns into one column.&lt;BR /&gt;
But if i have one more column with 10 occurences then i have to again use stack.&lt;BR /&gt;
then to merge them is problem..&lt;BR /&gt;
so can you suggest me how to go ahead</description>
      <pubDate>Mon, 06 Aug 2007 17:04:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-convert-multiple-columns-to-single-column/m-p/4038#M1277</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2007-08-06T17:04:57Z</dc:date>
    </item>
    <item>
      <title>Re: how to convert multiple columns to single column</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-convert-multiple-columns-to-single-column/m-p/4039#M1278</link>
      <description>Hi:&lt;BR /&gt;
  I forgot about the STACK task. But the reason the STACK task didn't pop into my thought process on this question is that it uses PROC TRANSPOSE and it's a bit harder to get your OTHER variables to carry along. With the STACK Task, you could pick more than one column to stack, but the resulting data set will look like this:&lt;BR /&gt;
[pre]&lt;BR /&gt;
name      ValueSource     StackedValue&lt;BR /&gt;
alan    sundry_val_003     300&lt;BR /&gt;
alan    sundry_val_002     200&lt;BR /&gt;
alan    sundry_val_001     100&lt;BR /&gt;
alan    sundry_code_003    ccc         &lt;BR /&gt;
alan    sundry_code_002    bbb         &lt;BR /&gt;
alan    sundry_code_001    aaa         &lt;BR /&gt;
bob     sundry_val_003     777&lt;BR /&gt;
bob     sundry_val_002     333&lt;BR /&gt;
bob     sundry_val_001     111&lt;BR /&gt;
bob     sundry_code_003    fff         &lt;BR /&gt;
bob     sundry_code_002    ccc         &lt;BR /&gt;
bob     sundry_code_001    aaa   &lt;BR /&gt;
[/pre]&lt;BR /&gt;
  &lt;BR /&gt;
You also said you wanted the values to be named sundry_code and sundry_val. And in order to get those names for your variables, you would have had to modify the code.&lt;BR /&gt;
  &lt;BR /&gt;
Your best bet at this point, is to contact Tech Support for help with the STACK task and then you still may have to modify the PROC TRANSPOSE code to get the right output dataset you want. But, if you're going to have to modify code, then you still might want to consider the ARRAY solution above in a code node. Tech Support could help you with either solution.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Mon, 06 Aug 2007 17:57:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-convert-multiple-columns-to-single-column/m-p/4039#M1278</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2007-08-06T17:57:27Z</dc:date>
    </item>
  </channel>
</rss>

