<?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: traspose rows to column identifying type of data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/traspose-rows-to-column-identifying-type-of-data/m-p/451810#M113975</link>
    <description>&lt;P&gt;You said "&lt;SPAN&gt;the problem is that some variable is numeric and some is character".&amp;nbsp; But your test data shows all character.&amp;nbsp; Now either you want all character across, or you need to convert those which should be numeric into number data.&amp;nbsp; I can't tell exactly what you expect as no required output, so I will assume that either a) you want all character variables out:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;proc transpose data=have out=want;
  by id;
  var value;
  id cod;
  idlabel cod;
run;&lt;/PRE&gt;
&lt;P&gt;Or that you want a mix of character and numeric, with the numeric type actually as numbers:&lt;/P&gt;
&lt;PRE&gt;/* convert those which are number */&lt;BR /&gt;data have;&lt;BR /&gt;  set have;&lt;BR /&gt;  if type="N" and lengthn(compress(value," ","d"))=0 then num_value=input(value,best.);&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc transpose data=have out=want1 prefix=n;
  by id;
  var num_value;
  id cod;
  idlabel cod;
  where type="N";
run;
proc transpose data=have out=want2 prefix=c;
  by id;
  var value;
  id cod;
  idlabel cod;
  where type="C";
run;
data want;
  merge want1 want2;
  by id;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;This will give you all C types as character, all N types as numeric, all across the page for each id.&lt;/P&gt;</description>
    <pubDate>Fri, 06 Apr 2018 09:34:16 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2018-04-06T09:34:16Z</dc:date>
    <item>
      <title>traspose rows to column identifying type of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/traspose-rows-to-column-identifying-type-of-data/m-p/451801#M113968</link>
      <description>&lt;P&gt;dear listers,&lt;/P&gt;
&lt;P&gt;I have a table with vertical data like this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;id=1; type='A'; cod='111'; value='123';output; &lt;BR /&gt;id=1; type='A'; cod='112'; value='ABC';output; &lt;BR /&gt;id=1; type='N'; cod='113'; value='065';output; &lt;BR /&gt;id=2; type='A'; cod='111'; value='123';output; &lt;BR /&gt;id=2; type='A'; cod='112'; value='ABC';output; &lt;BR /&gt;id=2; type='N'; cod='113'; value='433';output; &lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to transpose the dataset so that each cod becomes a variable within Id.&lt;/P&gt;
&lt;P&gt;the problem is that some variable is numeric and some is character. This is identified by type.&lt;/P&gt;
&lt;P&gt;another problem is that I don't know the lenght of each variable&lt;/P&gt;
&lt;P&gt;which is the best way to do it?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thank you very much in advance&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Apr 2018 08:56:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/traspose-rows-to-column-identifying-type-of-data/m-p/451801#M113968</guid>
      <dc:creator>ciro</dc:creator>
      <dc:date>2018-04-06T08:56:23Z</dc:date>
    </item>
    <item>
      <title>Re: traspose rows to column identifying type of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/traspose-rows-to-column-identifying-type-of-data/m-p/451802#M113969</link>
      <description>&lt;P&gt;If you data is not consistent then you would need two transposes with a differing prefix, maybe something like:&lt;/P&gt;
&lt;PRE&gt;proc transpose data=have out=want1 prefix=n;
  by id;
  var value;
  id cod;
  idlabel cod;
  where type="N";
run;
proc transpose data=have out=want2 prefix=c;
  by id;
  var value;
  id cod;
  idlabel cod;
  where type="C";
run;
data want;
  merge want1 want2;
  by id;
run;&lt;/PRE&gt;
&lt;P&gt;You may need a sort but hopefully not.&amp;nbsp; Alternatively you could create some array references and convert data as you go along, or have two sets of arrays, I think the two transposes is clearer however.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Apr 2018 09:01:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/traspose-rows-to-column-identifying-type-of-data/m-p/451802#M113969</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-04-06T09:01:52Z</dc:date>
    </item>
    <item>
      <title>Re: traspose rows to column identifying type of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/traspose-rows-to-column-identifying-type-of-data/m-p/451807#M113972</link>
      <description>&lt;P&gt;thank you for the idea of the two transpose. however in this case all the variables are set as characters.&lt;/P&gt;
&lt;P&gt;do you mean I need another step to convert the variables?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Apr 2018 09:26:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/traspose-rows-to-column-identifying-type-of-data/m-p/451807#M113972</guid>
      <dc:creator>ciro</dc:creator>
      <dc:date>2018-04-06T09:26:34Z</dc:date>
    </item>
    <item>
      <title>Re: traspose rows to column identifying type of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/traspose-rows-to-column-identifying-type-of-data/m-p/451810#M113975</link>
      <description>&lt;P&gt;You said "&lt;SPAN&gt;the problem is that some variable is numeric and some is character".&amp;nbsp; But your test data shows all character.&amp;nbsp; Now either you want all character across, or you need to convert those which should be numeric into number data.&amp;nbsp; I can't tell exactly what you expect as no required output, so I will assume that either a) you want all character variables out:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;proc transpose data=have out=want;
  by id;
  var value;
  id cod;
  idlabel cod;
run;&lt;/PRE&gt;
&lt;P&gt;Or that you want a mix of character and numeric, with the numeric type actually as numbers:&lt;/P&gt;
&lt;PRE&gt;/* convert those which are number */&lt;BR /&gt;data have;&lt;BR /&gt;  set have;&lt;BR /&gt;  if type="N" and lengthn(compress(value," ","d"))=0 then num_value=input(value,best.);&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc transpose data=have out=want1 prefix=n;
  by id;
  var num_value;
  id cod;
  idlabel cod;
  where type="N";
run;
proc transpose data=have out=want2 prefix=c;
  by id;
  var value;
  id cod;
  idlabel cod;
  where type="C";
run;
data want;
  merge want1 want2;
  by id;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;This will give you all C types as character, all N types as numeric, all across the page for each id.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Apr 2018 09:34:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/traspose-rows-to-column-identifying-type-of-data/m-p/451810#M113975</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-04-06T09:34:16Z</dc:date>
    </item>
    <item>
      <title>Re: traspose rows to column identifying type of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/traspose-rows-to-column-identifying-type-of-data/m-p/452172#M114089</link>
      <description>&lt;P&gt;Thanks, maybe my post was not that clear. The second is what I was looking for.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is a related issue. The character variables to be transposed have different lengths. Some are only flags (one character), some are strings up to 25 characters and some are in between. The problem is that I don't know the length in advance. Is there a way, in the transposed table to set the lenght of each variable?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 07 Apr 2018 09:47:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/traspose-rows-to-column-identifying-type-of-data/m-p/452172#M114089</guid>
      <dc:creator>ciro</dc:creator>
      <dc:date>2018-04-07T09:47:01Z</dc:date>
    </item>
    <item>
      <title>Re: traspose rows to column identifying type of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/traspose-rows-to-column-identifying-type-of-data/m-p/452431#M114188</link>
      <description>&lt;P&gt;There is no need to know the length.&amp;nbsp; The transposing variable will have its length, which is the maximum any value in that variable can be, each of the transposed created variables will have that length also.&amp;nbsp; If you then mean to alter those lengths, then that is a different matter entirely (and using compress=yes option on dataset is a far better method than going down that route).&lt;/P&gt;</description>
      <pubDate>Mon, 09 Apr 2018 08:15:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/traspose-rows-to-column-identifying-type-of-data/m-p/452431#M114188</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-04-09T08:15:30Z</dc:date>
    </item>
  </channel>
</rss>

