<?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: data transformation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/data-transformation/m-p/718338#M222303</link>
    <description>&lt;P&gt;This is not a one time job. I have been doing it manually in excel, but it would really help to automate it. The first data is available as shown, and I just need to extract the necessary information, so I can for example take the median of the 20 x values.&lt;/P&gt;</description>
    <pubDate>Wed, 10 Feb 2021 18:01:22 GMT</pubDate>
    <dc:creator>asasha</dc:creator>
    <dc:date>2021-02-10T18:01:22Z</dc:date>
    <item>
      <title>data transformation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-transformation/m-p/718266#M222249</link>
      <description>&lt;P&gt;I have a data like this (22x101):&lt;/P&gt;&lt;PRE&gt;     col1 col2 col3 ... col100
x    1.12 0.15 0.99 ... 0.38
t1   1          
t2             1        
t3   1                
...
t20            1&lt;/PRE&gt;&lt;P&gt;Each t row will have exactly one indicator=1. Each column corresponding to an x value may have none, one, or multiple indicator=1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, x=1.12 occurs at t1 and t3. And x=0.99 occurs at t2 and t20.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to collect the corresponding x where t has a 1 value and save them to a new data:&lt;/P&gt;&lt;PRE&gt;t1  1.12
t2  0.99
t3  1.12
...
t20 0.99&lt;/PRE&gt;&lt;P&gt;Please advise. Thank you.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Feb 2021 14:52:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-transformation/m-p/718266#M222249</guid>
      <dc:creator>asasha</dc:creator>
      <dc:date>2021-02-10T14:52:34Z</dc:date>
    </item>
    <item>
      <title>Re: data transformation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-transformation/m-p/718323#M222290</link>
      <description>&lt;P&gt;Is this a one time job?&lt;/P&gt;
&lt;P&gt;If yes, do it manually (e.g. in Excel).&lt;/P&gt;
&lt;P&gt;If not, ask for source fil(s) with proper structure.&lt;/P&gt;
&lt;P&gt;Last resort, I would try the data step.&lt;/P&gt;
&lt;P&gt;Put the first row in a retained array.&lt;/P&gt;
&lt;P&gt;Then use array processing for the t-rows tro find which value in the x-array to use.&lt;/P&gt;
&lt;P&gt;Untested though.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Feb 2021 17:27:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-transformation/m-p/718323#M222290</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2021-02-10T17:27:59Z</dc:date>
    </item>
    <item>
      <title>Re: data transformation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-transformation/m-p/718325#M222291</link>
      <description>&lt;P&gt;UNTESTED CODE&lt;/P&gt;
&lt;P&gt;Since you haven't given the column which contains x t1 t2 a variable name, I refer to it as the variable named firstcolumn.&lt;/P&gt;
&lt;P&gt;If you want tested code, you must provide data according to &lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;these instructions&lt;/A&gt; and not in any other form.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data x;
    set have(where=(upcase(firstcolumn)='X'));
    rename col1-col100=x1-x100;
run;

data want;
    if _n_=1 then set x;
    set have(where=(upcase(firstcolumn)=:'T'));
    array x x1-x100;
    first_occurence=whichn(1,of col:);
    wanted_value=x(first_occurence);
    keep firstcolumn wanted_value;
run;
    
    &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 Feb 2021 17:40:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-transformation/m-p/718325#M222291</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-02-10T17:40:49Z</dc:date>
    </item>
    <item>
      <title>Re: data transformation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-transformation/m-p/718332#M222297</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/338636"&gt;@asasha&lt;/a&gt;,&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/338636"&gt;@asasha&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have a data like this (22x101): ...&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This sounds like you haven't read the raw data yet? So you may want to create the desired dataset in one step (using &lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13674" target="_blank" rel="noopener"&gt;LinusH&lt;/A&gt;'s plan):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let n=4; /* n=100 with your real data */

data want(keep=id v);
array col[&amp;amp;n];
retain col:;
input id $ @;
if _n_=1 then input col[*];
else do;
  input z1-z&amp;amp;n;
  v=col[whichn(1, of z:)];
  output;
end;
cards;
x    1.12 0.15 0.99 0.38
t1   1     .    .    .
t2    .    .   1     .
t3   1     .    .    .
t20   .    .   1     .
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 Feb 2021 17:52:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-transformation/m-p/718332#M222297</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-02-10T17:52:36Z</dc:date>
    </item>
    <item>
      <title>Re: data transformation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-transformation/m-p/718338#M222303</link>
      <description>&lt;P&gt;This is not a one time job. I have been doing it manually in excel, but it would really help to automate it. The first data is available as shown, and I just need to extract the necessary information, so I can for example take the median of the 20 x values.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Feb 2021 18:01:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-transformation/m-p/718338#M222303</guid>
      <dc:creator>asasha</dc:creator>
      <dc:date>2021-02-10T18:01:22Z</dc:date>
    </item>
    <item>
      <title>Re: data transformation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-transformation/m-p/718343#M222307</link>
      <description>&lt;P&gt;In which form is it available?&lt;/P&gt;
&lt;P&gt;If SAS dataset: post a data step with datalines that creates this dataset in our SAS session(s).&lt;/P&gt;
&lt;P&gt;If text file: copy/paste the text into a window opened with this button:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Bildschirmfoto 2020-04-07 um 08.32.59.jpg" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/54552i914D97BE1B0F21E5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Bildschirmfoto 2020-04-07 um 08.32.59.jpg" alt="Bildschirmfoto 2020-04-07 um 08.32.59.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;If Excel: attach the Excel file.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Feb 2021 18:09:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-transformation/m-p/718343#M222307</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-02-10T18:09:02Z</dc:date>
    </item>
    <item>
      <title>Re: data transformation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-transformation/m-p/718454#M222358</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13674"&gt;@LinusH&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's an exact subset example in cvs (22 rows, 17 columns). Alternatively, I just need to extract all 20 of the x's, regardless of which t they correspond to. Like I said, I have 100 of them (not just 15) and they are spread around. Just need the ones that were selected for t.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="sas"&gt;Parameter,t,col1,col2,col3,col4,col5,col6,col7,col8,col9,col10,col11,col12,col13,col14,col15
x,,0.98,0.882,0.7938,0.71442,0.642978,0.5786802,0.52081218,0.468730962,0.421857866,0.379672079,0.341704871,0.307534384,0.276780946,0.249102851,0.224192566
Opt,t1,,,,,,,1,,,,,,,,
Opt,t2,,,,,,,,,,1,,,,,
Opt,t3,,,,,,,,,,1,,,,,
Opt,t4,,,,,1,,,,,,,,,,
Opt,t5,,,,,,,,,,1,,,,,
Opt,t6,,,,,,,,1,,,,,,,
Opt,t7,,,,,,,,1,,,,,,,
Opt,t8,,,,,,,,,,,,1,,,
Opt,t9,,,,,,,,,,,1,,,,
Opt,t10,,,,,,,,1,,,,,,,
Opt,t11,,,,,,,,,1,,,,,,
Opt,t12,,,,,,,,,1,,,,,,
Opt,t13,,,,,,,,,,,1,,,,
Opt,t14,,,,1,,,,,,,,,,,
Opt,t15,,,,,,,1,,,,,,,,
Opt,t16,,1,,,,,,,,,,,,,
Opt,t17,,,,,,1,,,,,,,,,
Opt,t18,,,,,,,,,,1,,,,,
Opt,t19,,,,,,,,,,,,,1,,
Opt,t20,,,,,,1,,,,,,,,,&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Feb 2021 02:46:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-transformation/m-p/718454#M222358</guid>
      <dc:creator>asasha</dc:creator>
      <dc:date>2021-02-11T02:46:38Z</dc:date>
    </item>
    <item>
      <title>Re: data transformation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-transformation/m-p/718495#M222375</link>
      <description>&lt;P&gt;See this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
infile datalines dlm="," dsd truncover;
input
  Parameter $
  t $
  col1-col15
;
retain t1-t15;
array col {*} col1-col15;
array ta {*} t1-t15;
if parameter = "x"
then do;
  do i = 1 to dim(col);
    ta{i} = col{i};
  end;
end;
else do;
  do i = 1 to dim(col);
    if col{i}
    then do;
      x = ta{i};
      leave;
    end;
  end;
  output;
end;
keep t x;
datalines;
x,,0.98,0.882,0.7938,0.71442,0.642978,0.5786802,0.52081218,0.468730962,0.421857866,0.379672079,0.341704871,0.307534384,0.276780946,0.249102851,0.224192566
Opt,t1,,,,,,,1,,,,,,,,
Opt,t2,,,,,,,,,,1,,,,,
Opt,t3,,,,,,,,,,1,,,,,
Opt,t4,,,,,1,,,,,,,,,,
Opt,t5,,,,,,,,,,1,,,,,
Opt,t6,,,,,,,,1,,,,,,,
Opt,t7,,,,,,,,1,,,,,,,
Opt,t8,,,,,,,,,,,,1,,,
Opt,t9,,,,,,,,,,,1,,,,
Opt,t10,,,,,,,,1,,,,,,,
Opt,t11,,,,,,,,,1,,,,,,
Opt,t12,,,,,,,,,1,,,,,,
Opt,t13,,,,,,,,,,,1,,,,
Opt,t14,,,,1,,,,,,,,,,,
Opt,t15,,,,,,,1,,,,,,,,
Opt,t16,,1,,,,,,,,,,,,,
Opt,t17,,,,,,1,,,,,,,,,
Opt,t18,,,,,,,,,,1,,,,,
Opt,t19,,,,,,,,,,,,,1,,
Opt,t20,,,,,,1,,,,,,,,,
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 11 Feb 2021 07:38:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-transformation/m-p/718495#M222375</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-02-11T07:38:04Z</dc:date>
    </item>
    <item>
      <title>Re: data transformation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-transformation/m-p/718538#M222395</link>
      <description>&lt;P&gt;This data does not match the originally provided data, as the first column originally provided has a value of x in the first row, but not t1 in the second row.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Nevertheless, with minor changes, the code I provided should still work.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Feb 2021 11:43:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-transformation/m-p/718538#M222395</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-02-11T11:43:34Z</dc:date>
    </item>
    <item>
      <title>Re: data transformation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-transformation/m-p/718578#M222409</link>
      <description>&lt;P&gt;this didn't work as my t is up to 20, and my col is up to 15 (or 100).&lt;/P&gt;</description>
      <pubDate>Thu, 11 Feb 2021 13:50:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-transformation/m-p/718578#M222409</guid>
      <dc:creator>asasha</dc:creator>
      <dc:date>2021-02-11T13:50:05Z</dc:date>
    </item>
    <item>
      <title>Re: data transformation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-transformation/m-p/718585#M222411</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/338636"&gt;@asasha&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;this didn't work ...&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;For your future benefit, if you say "didn't work" and do not provide the LOG or the DATA to show what you did, and why it didn't work, then you don't get an answer. (I don't have an answer for you right now.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, &lt;STRONG&gt;show us the LOG&lt;/STRONG&gt; (and if there is incorrect output, show us the incorrect output as well)&lt;/P&gt;</description>
      <pubDate>Thu, 11 Feb 2021 13:56:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-transformation/m-p/718585#M222411</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-02-11T13:56:54Z</dc:date>
    </item>
    <item>
      <title>Re: data transformation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-transformation/m-p/718587#M222412</link>
      <description>&lt;P&gt;The number of t observations is irrelevant with my code, and it should be obvious where to implement a larger number of columns.&lt;/P&gt;
&lt;LI-SPOILER&gt;Simply replace the 15 in the array definitions with 100&lt;/LI-SPOILER&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/338636"&gt;@asasha&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;this didn't work as my t is up to 20, and my col is up to 15 (or 100).&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Feb 2021 14:03:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-transformation/m-p/718587#M222412</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-02-11T14:03:53Z</dc:date>
    </item>
  </channel>
</rss>

