<?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: Dataset Transformation Help Wanted in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Dataset-Transformation-Help-Wanted/m-p/807709#M318489</link>
    <description>&lt;P&gt;No idea how this relates to making a graphic.&lt;/P&gt;
&lt;P&gt;But you just need a DO loop.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input Target $ Tx Ty Station $ k;
datalines;
0/0 0 0 A 1
0/0 0 0 B 0
0/0 0 0 C 0
0/1 0 1 A 1
0/1 0 1 B 1
0/1 0 1 C 0
1/0 1 0 A 1
1/0 1 0 B 1
1/0 1 0 C 1
;

data want;
  do until(last.target) ;
    set have ;
    by target;
    array S[3] $8;
    ksum=sum(ksum,k);
    if k then S[ksum]=station;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;Obs    Target    Tx    Ty    Station    k    S1    S2    S3    ksum

 1      0/0       0     0       C       0    A                   1
 2      0/1       0     1       C       0    A     B             2
 3      1/0       1     0       C       1    A     B     C       3

&lt;/PRE&gt;
&lt;P&gt;Change the dimension of the ARRAY if there might be more than three stations for a target you need to record.&lt;/P&gt;</description>
    <pubDate>Thu, 14 Apr 2022 05:24:44 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-04-14T05:24:44Z</dc:date>
    <item>
      <title>Dataset Transformation Help Wanted</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dataset-Transformation-Help-Wanted/m-p/807695#M318477</link>
      <description>&lt;P&gt;I need some help getting a dataset transformed.&amp;nbsp; The goal is to take dataset HAVE and turn it into dataset WANT. See below for details.&amp;nbsp; I don't know how to accomplish this task.&amp;nbsp; Thanks in advance for your help.&lt;/P&gt;
&lt;P&gt;Gene&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;input Target $ Tx Ty Station $ k;&lt;BR /&gt;datalines;&lt;BR /&gt;0/0 0 0 A 1&lt;BR /&gt;0/0 0 0 B 0&lt;BR /&gt;0/0 0 0 C 0 &lt;BR /&gt;0/1 0 1 A 1&lt;BR /&gt;0/1 0 1 B 1&lt;BR /&gt;0/1 0 1 C 0&lt;BR /&gt;1/0 1 0 A 1&lt;BR /&gt;1/0 1 0 B 1&lt;BR /&gt;1/0 1 0 C 1&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;proc sort data=have;&lt;BR /&gt;by target;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;/*Need code here (Proc Transpose?) that produces the following dataset from dataset Have&lt;BR /&gt;where ksum is the sum of k for each unique Target value*/&lt;/P&gt;
&lt;P&gt;Data want;&lt;BR /&gt;input Target $ Tx Ty ksum S1 $ S2 $ S3 $;&lt;BR /&gt;datalines;&lt;BR /&gt;0/0 0 0 1 A . .&lt;BR /&gt;0/1 0 1 2 A B .&lt;BR /&gt;1/0 1 0 3 A B C&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/* The goal is to&amp;nbsp; create a scatter plot of Tx by Ty grouped by ksum with datatips&lt;BR /&gt;that display Target,ksum,S1,S2,S3.&amp;nbsp; See below*/&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;ods graphics on/imagemap;&lt;BR /&gt;Proc SGPlot data=want;&lt;BR /&gt;scatter x=tx y=ty/group=ksum tip=(Target ksum S1 S2 S3);&lt;BR /&gt;xaxis min=-2 max=2;&lt;BR /&gt;yaxis min=-2 max=2;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Apr 2022 23:45:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dataset-Transformation-Help-Wanted/m-p/807695#M318477</guid>
      <dc:creator>genemroz</dc:creator>
      <dc:date>2022-04-13T23:45:18Z</dc:date>
    </item>
    <item>
      <title>Re: Dataset Transformation Help Wanted</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dataset-Transformation-Help-Wanted/m-p/807697#M318479</link>
      <description>&lt;P&gt;Can you indicate exactly which rows/values you are summing to get the output data set?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From what little I understand there is more than one way to get several of those "sums".&lt;/P&gt;
&lt;P&gt;This seems to work for your example data.&lt;/P&gt;
&lt;P&gt;I'm not sure how extensible it might be.&lt;/P&gt;
&lt;PRE&gt;data want;
   set have;
   array s(3) $;
   retain ksum s1-s3 counter;
   by target;
   if first.target then do;
      call missing(ksum, of s(*),counter);

   end;
   if k then do;
      counter+1;
      ksum+k;
      s[counter] = station;
   end;
   if last.target then output;
   drop station k counter;
run;


&lt;/PRE&gt;
&lt;P&gt;You might want to use either a custom format to display something like N/A for the S variables when the value is missing or set Options missing=' '; before generating the graph to make slightly cleaner tip appearance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Apr 2022 00:26:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dataset-Transformation-Help-Wanted/m-p/807697#M318479</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-04-14T00:26:20Z</dc:date>
    </item>
    <item>
      <title>Re: Dataset Transformation Help Wanted</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dataset-Transformation-Help-Wanted/m-p/807698#M318480</link>
      <description>&lt;P&gt;If K is always a 1 or 0, then as ksum increments, then next S variable (S1, S2, S3) is assigned the corresponding station value:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Target $ Tx Ty Station $ k;
datalines;
0/0 0 0 A 1
0/0 0 0 B 0
0/0 0 0 C 0
0/1 0 1 A 1
0/1 0 1 B 1
0/1 0 1 C 0
1/0 1 0 A 1
1/0 1 0 B 1
1/0 1 0 C 1
run;
data want (drop=k station);
  set have;
  by target;
  retain ksum 0 s1-s3 '  ';
  array s{3};
  if first.target then call missing (ksum,s1,s2,s3);
  ksum+k;
  if k=1 then s{ksum}=station;
  if last.target;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Apr 2022 01:35:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dataset-Transformation-Help-Wanted/m-p/807698#M318480</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-04-14T01:35:05Z</dc:date>
    </item>
    <item>
      <title>Re: Dataset Transformation Help Wanted</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dataset-Transformation-Help-Wanted/m-p/807709#M318489</link>
      <description>&lt;P&gt;No idea how this relates to making a graphic.&lt;/P&gt;
&lt;P&gt;But you just need a DO loop.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input Target $ Tx Ty Station $ k;
datalines;
0/0 0 0 A 1
0/0 0 0 B 0
0/0 0 0 C 0
0/1 0 1 A 1
0/1 0 1 B 1
0/1 0 1 C 0
1/0 1 0 A 1
1/0 1 0 B 1
1/0 1 0 C 1
;

data want;
  do until(last.target) ;
    set have ;
    by target;
    array S[3] $8;
    ksum=sum(ksum,k);
    if k then S[ksum]=station;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;Obs    Target    Tx    Ty    Station    k    S1    S2    S3    ksum

 1      0/0       0     0       C       0    A                   1
 2      0/1       0     1       C       0    A     B             2
 3      1/0       1     0       C       1    A     B     C       3

&lt;/PRE&gt;
&lt;P&gt;Change the dimension of the ARRAY if there might be more than three stations for a target you need to record.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Apr 2022 05:24:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dataset-Transformation-Help-Wanted/m-p/807709#M318489</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-04-14T05:24:44Z</dc:date>
    </item>
    <item>
      <title>Re: Dataset Transformation Help Wanted</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dataset-Transformation-Help-Wanted/m-p/807784#M318526</link>
      <description>&lt;P&gt;Thanks to all who responded with solutions.&amp;nbsp; They all work but I will mark ballardw's solution as "accepted" since his was first.&amp;nbsp; Thanks again for your help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Gene&lt;/P&gt;</description>
      <pubDate>Thu, 14 Apr 2022 12:26:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dataset-Transformation-Help-Wanted/m-p/807784#M318526</guid>
      <dc:creator>genemroz</dc:creator>
      <dc:date>2022-04-14T12:26:55Z</dc:date>
    </item>
  </channel>
</rss>

