<?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: creating new table in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/creating-new-table/m-p/733046#M28525</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you would have provided the community members with your data using a datastep with datalines (instead of a screenshot), you would have got tons of solutions meanwhile.&lt;/P&gt;
&lt;P&gt;I quickly assembled something using invented data.&lt;/P&gt;
&lt;P&gt;The code is not generic at all!!&lt;/P&gt;
&lt;P&gt;Ideally you query your available data for the max n° of rows for an id and you wrap everything in a macro (with a do-loop) to avoid doing 10 times the same thing.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyway, it's a weird transpose. I couldn't rapidly fix it with a proc transpose. But I guess that's because of lack of time (on my side). proc transpose can definitely do this.&lt;/P&gt;
&lt;P&gt;Let me know if you cannot make this code more dense and generic by using a macro and I will do it for you (but not today, I need to go for dinner &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 input id var1 var2 var3;
 cards;
3 0 1 2
3 1 2 1
3 4 8 1
4 0 1 2
4 1 2 1
4 4 8 1
;
run;

proc expand data=have out=have_expand;
 by id;
 convert var1 / transform=(CUSUM);
 convert var2 / transform=(CUSUM);
 convert var3 / transform=(CUSUM);
run;

data have_expand; set have_expand; time=time+1; run;
data time1(rename=(var1=var1_1 var2=var2_1 var3=var3_1)); set have_expand; where time=1; run;
data time2(rename=(var1=var1_2 var2=var2_2 var3=var3_2)); set have_expand; where time=2; run;
data time3(rename=(var1=var1_3 var2=var2_3 var3=var3_3)); set have_expand; where time=3; run;

data want(drop=time);
 merge time1 time2 time3;
run;
/* end of program */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Cheers,&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 12 Apr 2021 17:15:36 GMT</pubDate>
    <dc:creator>sbxkoenk</dc:creator>
    <dc:date>2021-04-12T17:15:36Z</dc:date>
    <item>
      <title>creating new table</title>
      <link>https://communities.sas.com/t5/New-SAS-User/creating-new-table/m-p/733015#M28521</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have such data&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Nini1_0-1618237718771.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/57404iC9AE703C65D8390D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Nini1_0-1618237718771.png" alt="Nini1_0-1618237718771.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;and want to write code that will give me this table.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Nini1_1-1618237765369.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/57405i66864A486675CF73/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Nini1_1-1618237765369.png" alt="Nini1_1-1618237765369.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I tried some but did not work. Could you please help me to write the code that will give me this result?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Apr 2021 14:33:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/creating-new-table/m-p/733015#M28521</guid>
      <dc:creator>Nini1</dc:creator>
      <dc:date>2021-04-12T14:33:56Z</dc:date>
    </item>
    <item>
      <title>Re: creating new table</title>
      <link>https://communities.sas.com/t5/New-SAS-User/creating-new-table/m-p/733020#M28522</link>
      <description>&lt;P&gt;You need to describe what the process is to have a chance.&lt;/P&gt;
&lt;P&gt;For example, how does Var1_2 or Var1_3 get a value of "2" for Id=1 when none of the values shown for Id 1 in the "have" data have a value of 2. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please post data as text, preferably as data step code. We can't code from pictures.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Apr 2021 15:05:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/creating-new-table/m-p/733020#M28522</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-04-12T15:05:05Z</dc:date>
    </item>
    <item>
      <title>Re: creating new table</title>
      <link>https://communities.sas.com/t5/New-SAS-User/creating-new-table/m-p/733026#M28523</link>
      <description>sorry, I missed this in description. Var1_1 is Var1's first row, Var1_2 is summing var 1's first and second rows and so on for each client. the same for other variables</description>
      <pubDate>Mon, 12 Apr 2021 15:28:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/creating-new-table/m-p/733026#M28523</guid>
      <dc:creator>Nini1</dc:creator>
      <dc:date>2021-04-12T15:28:39Z</dc:date>
    </item>
    <item>
      <title>Re: creating new table</title>
      <link>https://communities.sas.com/t5/New-SAS-User/creating-new-table/m-p/733046#M28525</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you would have provided the community members with your data using a datastep with datalines (instead of a screenshot), you would have got tons of solutions meanwhile.&lt;/P&gt;
&lt;P&gt;I quickly assembled something using invented data.&lt;/P&gt;
&lt;P&gt;The code is not generic at all!!&lt;/P&gt;
&lt;P&gt;Ideally you query your available data for the max n° of rows for an id and you wrap everything in a macro (with a do-loop) to avoid doing 10 times the same thing.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyway, it's a weird transpose. I couldn't rapidly fix it with a proc transpose. But I guess that's because of lack of time (on my side). proc transpose can definitely do this.&lt;/P&gt;
&lt;P&gt;Let me know if you cannot make this code more dense and generic by using a macro and I will do it for you (but not today, I need to go for dinner &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 input id var1 var2 var3;
 cards;
3 0 1 2
3 1 2 1
3 4 8 1
4 0 1 2
4 1 2 1
4 4 8 1
;
run;

proc expand data=have out=have_expand;
 by id;
 convert var1 / transform=(CUSUM);
 convert var2 / transform=(CUSUM);
 convert var3 / transform=(CUSUM);
run;

data have_expand; set have_expand; time=time+1; run;
data time1(rename=(var1=var1_1 var2=var2_1 var3=var3_1)); set have_expand; where time=1; run;
data time2(rename=(var1=var1_2 var2=var2_2 var3=var3_2)); set have_expand; where time=2; run;
data time3(rename=(var1=var1_3 var2=var2_3 var3=var3_3)); set have_expand; where time=3; run;

data want(drop=time);
 merge time1 time2 time3;
run;
/* end of program */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Cheers,&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Apr 2021 17:15:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/creating-new-table/m-p/733046#M28525</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2021-04-12T17:15:36Z</dc:date>
    </item>
    <item>
      <title>Re: creating new table</title>
      <link>https://communities.sas.com/t5/New-SAS-User/creating-new-table/m-p/733048#M28526</link>
      <description>Also, I guess the real variable names are not var1, var2 and var3. If you have 1000+ variables with non-common names (possibly up to 32 chars for the name), you definitely need to transform this into more generic code. I can do that tomorrow if you cannot sort it out.&lt;BR /&gt;Koen&lt;BR /&gt;</description>
      <pubDate>Mon, 12 Apr 2021 17:22:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/creating-new-table/m-p/733048#M28526</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2021-04-12T17:22:08Z</dc:date>
    </item>
    <item>
      <title>Re: creating new table</title>
      <link>https://communities.sas.com/t5/New-SAS-User/creating-new-table/m-p/733065#M28528</link>
      <description>&lt;P&gt;I'm wondering what the benefit of this transformation is. Generally, such a transformation, where an sequence number is placed into a variable name, is not recommended because future use of this data set would proceed more easily without such a transformation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This seems like the &lt;A href="https://xyproblem.info/" target="_self"&gt;X-Y problem&lt;/A&gt;, where someone wants to accomplish something, and then decides somewhere along the way they have to perform a task, when in reality that task doesn't need to be performed, there are better and easier paths to the end result.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Could you tell us what you want to do with this data after the transformation is performed? Also, regarding the output you show, do you want this to be a table that can be included in an output document, or do you want this to be a data set for further analysis?&lt;/P&gt;</description>
      <pubDate>Mon, 12 Apr 2021 18:28:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/creating-new-table/m-p/733065#M28528</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-04-12T18:28:06Z</dc:date>
    </item>
    <item>
      <title>Creating new table</title>
      <link>https://communities.sas.com/t5/New-SAS-User/creating-new-table/m-p/733091#M28541</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have such data&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Nini1_0-1618254185988.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/57421iC56CB3B85F99E06A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Nini1_0-1618254185988.png" alt="Nini1_0-1618254185988.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and want to write code that will give me this table.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Nini1_1-1618254185982.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/57420iB269056952B9CDAE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Nini1_1-1618254185982.png" alt="Nini1_1-1618254185982.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;For first person var1_1's first entry equals to var1's first entry.var1_2's entry equals to var1's first and second entries (1+1) ,var1_3's entry equals&amp;nbsp;1+1+0. It's the same logic for other variables and other persons.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried the code below but did not work.&lt;/P&gt;
&lt;P&gt;Proc sort data = data have;by id;run;&lt;BR /&gt;Data data_want_1;&lt;BR /&gt;do until (last.id);&lt;BR /&gt;set data have;&lt;BR /&gt;by id;&lt;/P&gt;
&lt;P&gt;If First.id then do;&lt;BR /&gt;var1_=First.var1;&lt;BR /&gt;end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;if var1=1 then var1_=var1+1;else var1_=var1+0;&lt;/P&gt;
&lt;P&gt;Array A_var1_{*} var1_1-var1_3;&lt;BR /&gt;A_var1_{Count} =var1_;end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could you please help me to write the code that will give me this result?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Mon, 12 Apr 2021 19:42:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/creating-new-table/m-p/733091#M28541</guid>
      <dc:creator>Nini1</dc:creator>
      <dc:date>2021-04-12T19:42:23Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new table</title>
      <link>https://communities.sas.com/t5/New-SAS-User/creating-new-table/m-p/733110#M28542</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/344950"&gt;@Nini1&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for asking your questions in the SAS Communities! It looks like this question is the same one you posted in "&lt;A href="https://communities.sas.com/t5/New-SAS-User/creating-new-table/m-p/733015" target="_self"&gt;Creating new table&lt;/A&gt;," but with more details. Can you add a comment to &lt;A href="https://communities.sas.com/t5/New-SAS-User/creating-new-table/m-p/733015" target="_self"&gt;the original post&lt;/A&gt; and include these additional details? That way everyone following that post will be aware. After you've done that, feel free to delete this post.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;P&gt;Anna&lt;/P&gt;</description>
      <pubDate>Mon, 12 Apr 2021 20:52:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/creating-new-table/m-p/733110#M28542</guid>
      <dc:creator>AnnaBrown</dc:creator>
      <dc:date>2021-04-12T20:52:21Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new table</title>
      <link>https://communities.sas.com/t5/New-SAS-User/creating-new-table/m-p/733118#M28543</link>
      <description>These seem like running totals. Any particular reason you need to flip the data to do it? What are you planning to do next? I suspect there are many ways to simplify this process.</description>
      <pubDate>Mon, 12 Apr 2021 21:19:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/creating-new-table/m-p/733118#M28543</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-04-12T21:19:01Z</dc:date>
    </item>
    <item>
      <title>Re: creating new table</title>
      <link>https://communities.sas.com/t5/New-SAS-User/creating-new-table/m-p/733228#M28544</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/344950"&gt;@Nini1&lt;/a&gt; : i have merged your posts.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Apr 2021 07:08:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/creating-new-table/m-p/733228#M28544</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-04-13T07:08:51Z</dc:date>
    </item>
    <item>
      <title>Re: creating new table</title>
      <link>https://communities.sas.com/t5/New-SAS-User/creating-new-table/m-p/733294#M28557</link>
      <description>&lt;P&gt;The simplest way is using proc summary.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 input id var1 var2 var3;
 cards;
3 0 1 2
3 1 2 1
3 4 8 1
4 0 1 2
4 1 2 1
4 4 8 1
;
run;
proc sql noprint;
select max(n) into :n
 from (select count(*) as n from have group by id);
quit;
proc summary data=have;
by id;
output out=want(drop=_type_ _freq_) idgroup(out[&amp;amp;n] (var1-var3)=);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 13 Apr 2021 12:35:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/creating-new-table/m-p/733294#M28557</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-04-13T12:35:59Z</dc:date>
    </item>
    <item>
      <title>Re: creating new table</title>
      <link>https://communities.sas.com/t5/New-SAS-User/creating-new-table/m-p/733298#M28558</link>
      <description>Great! I hadn't thought about that solution. It has been a long time since I have used the &amp;lt;&amp;lt;idgroup&amp;gt;&amp;gt; in the output statement of PROC SUMMARY (or PROC MEANS).&lt;BR /&gt;Thanks,&lt;BR /&gt;Koen</description>
      <pubDate>Tue, 13 Apr 2021 12:45:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/creating-new-table/m-p/733298#M28558</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2021-04-13T12:45:55Z</dc:date>
    </item>
    <item>
      <title>Re: creating new table</title>
      <link>https://communities.sas.com/t5/New-SAS-User/creating-new-table/m-p/733299#M28559</link>
      <description>Another two simple ways are &lt;BR /&gt;1) Double PROC TRANSPOSE&lt;BR /&gt;2) MERGE Skill . I submit a paper to talk about this skill:&lt;BR /&gt;&lt;A href="https://support.sas.com/resources/papers/proceedings15/2785-2015.pdf" target="_blank"&gt;https://support.sas.com/resources/papers/proceedings15/2785-2015.pdf&lt;/A&gt;</description>
      <pubDate>Tue, 13 Apr 2021 12:50:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/creating-new-table/m-p/733299#M28559</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-04-13T12:50:23Z</dc:date>
    </item>
  </channel>
</rss>

