<?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: Transformation structure of data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Transformation-structure-of-data/m-p/697838#M213342</link>
    <description>&lt;BR /&gt;there is another way to loop variable list that doesn't depend on x1 to x5&lt;BR /&gt;because my variables in reality have other names</description>
    <pubDate>Tue, 10 Nov 2020 10:00:35 GMT</pubDate>
    <dc:creator>mazouz</dc:creator>
    <dc:date>2020-11-10T10:00:35Z</dc:date>
    <item>
      <title>Transformation structure of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transformation-structure-of-data/m-p/697831#M213337</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have this table :&lt;/P&gt;&lt;PRE&gt;data have;
   input x1 x2 x3 x4 x5;
cards;
1 . . . .
1 . . . .
4 . . . .
5 . . . .
1 . . . .
. 2 . . .
. 1 . . .
. 2 . . .
. 3 . . .
. 4 . . .
. . 4 . .
. . 4 . .
. . 1 . .
. . 4 . .
. . 4 . .
. . . 2 .
. . . 3 .
. . . 4 .
. . . 1 .
. . . 3 .
. . . . 2
. . . . 4
. . . . 3
. . . . 2
. . . . 1
;
run;&lt;/PRE&gt;&lt;P&gt;I want to transform the table like that:&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;columns&lt;/TD&gt;&lt;TD&gt;x1&lt;/TD&gt;&lt;TD&gt;x2&lt;/TD&gt;&lt;TD&gt;x3&lt;/TD&gt;&lt;TD&gt;x4&lt;/TD&gt;&lt;TD&gt;x5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;x1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;x2&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;x3&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;x4&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;x5&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Tue, 10 Nov 2020 09:38:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transformation-structure-of-data/m-p/697831#M213337</guid>
      <dc:creator>mazouz</dc:creator>
      <dc:date>2020-11-10T09:38:46Z</dc:date>
    </item>
    <item>
      <title>Re: Transformation structure of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transformation-structure-of-data/m-p/697833#M213338</link>
      <description>&lt;P&gt;Is your actual problem this simple? Or is this a representation of some more advanced problem?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it is this simple:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   columns = cats('x', _N_);
   merge have (keep=x1 where=(x1))
         have (keep=x2 where=(x2))
         have (keep=x3 where=(x3))
         have (keep=x4 where=(x4))
         have (keep=x5 where=(x5));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;columns x1 x2 x3 x4 x5 
x1      1  2  4  2  2 
x2      1  1  4  3  4 
x3      4  2  1  4  3 
x4      5  3  4  1  2 
x5      1  4  4  3  1 
&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Nov 2020 09:53:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transformation-structure-of-data/m-p/697833#M213338</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-11-10T09:53:33Z</dc:date>
    </item>
    <item>
      <title>Re: Transformation structure of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transformation-structure-of-data/m-p/697835#M213339</link>
      <description>it is the result of a program that I made but I want to transform the data structure in order to be more readable</description>
      <pubDate>Tue, 10 Nov 2020 09:52:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transformation-structure-of-data/m-p/697835#M213339</guid>
      <dc:creator>mazouz</dc:creator>
      <dc:date>2020-11-10T09:52:56Z</dc:date>
    </item>
    <item>
      <title>Re: Transformation structure of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transformation-structure-of-data/m-p/697836#M213340</link>
      <description>&lt;P&gt;Ok. If you want, we can take a look at 'that program you made' and make it produce readable results.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Otherwise, see if my program above helps you.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Nov 2020 09:55:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transformation-structure-of-data/m-p/697836#M213340</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-11-10T09:55:04Z</dc:date>
    </item>
    <item>
      <title>Re: Transformation structure of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transformation-structure-of-data/m-p/697837#M213341</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro datasets;
%do i = 1 %to 5;
  have (keep=x&amp;amp;i. where=(x&amp;amp;i. ne .))
%end;
%mend;

data want;
length columns $8;
merge
  %datasets
;
columns = cats("x",_n_);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Nov 2020 09:55:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transformation-structure-of-data/m-p/697837#M213341</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-11-10T09:55:53Z</dc:date>
    </item>
    <item>
      <title>Re: Transformation structure of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transformation-structure-of-data/m-p/697838#M213342</link>
      <description>&lt;BR /&gt;there is another way to loop variable list that doesn't depend on x1 to x5&lt;BR /&gt;because my variables in reality have other names</description>
      <pubDate>Tue, 10 Nov 2020 10:00:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transformation-structure-of-data/m-p/697838#M213342</guid>
      <dc:creator>mazouz</dc:creator>
      <dc:date>2020-11-10T10:00:35Z</dc:date>
    </item>
    <item>
      <title>Re: Transformation structure of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transformation-structure-of-data/m-p/697840#M213344</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I try this but didn't work&lt;/P&gt;&lt;PRE&gt;%macro datasets;
%let list=CTT_ID
SOUU_ID
RET_ID
REGT_LIBE
TIET_IDCCT_ID
SOO_ID
RE_ID
RG_LIBE
TE_ID
CT_ID
OU_ID
EG_ID
R_LIB
TE_ID
CT_ID
SU_ID
ERG_ID
RRG_LIBE
TTE_ID
%do index = 1 %to %sysfunc(countw(&amp;amp;list,%str( )));
%let J =%scan(&amp;amp;list,&amp;amp;index,%str( ));
have (keep=J where=(J ne .))
%end;
%mend;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Nov 2020 10:16:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transformation-structure-of-data/m-p/697840#M213344</guid>
      <dc:creator>mazouz</dc:creator>
      <dc:date>2020-11-10T10:16:04Z</dc:date>
    </item>
    <item>
      <title>Re: Transformation structure of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transformation-structure-of-data/m-p/697849#M213347</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro datasets;
%local list index j; /* good behavior of macro to prevent side effects */
%let list=
CTT_ID
SOUU_ID
RET_ID
REGT_LIBE
TIET_IDCCT_ID
SOO_ID
RE_ID
RG_LIBE
TE_ID
CT_ID
OU_ID
EG_ID
R_LIB
TE_ID
CT_ID
SU_ID
ERG_ID
RRG_LIBE
TTE_ID
; /* semicolon needed to end the %let */
%do index = 1 %to %sysfunc(countw(&amp;amp;list)); /* blank is the default delimiter of countw */
  %let J = %scan(&amp;amp;list,&amp;amp;index); /* same for %scan */
  have (keep=&amp;amp;J where=(&amp;amp;J ne .)) /* correctly address macro variables */
%end;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Nov 2020 11:06:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transformation-structure-of-data/m-p/697849#M213347</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-11-10T11:06:16Z</dc:date>
    </item>
    <item>
      <title>Re: Transformation structure of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transformation-structure-of-data/m-p/697863#M213356</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;I dont know how to apply the code I have errors&lt;/P&gt;&lt;PRE&gt;data have;
   input a b c d e;
cards;
1 . . . .
1 . . . .
4 . . . .
5 . . . .
1 . . . .
. 2 . . .
. 1 . . .
. 2 . . .
. 3 . . .
. 4 . . .
. . 4 . .
. . 4 . .
. . 1 . .
. . 4 . .
. . 4 . .
. . . 2 .
. . . 3 .
. . . 4 .
. . . 1 .
. . . 3 .
. . . . 2
. . . . 4
. . . . 3
. . . . 2
. . . . 1
;
run;
%let list= a b c d e;
%macro datasets;
%local list index J; 
%do index = 1 %to %sysfunc(countw(&amp;amp;list)); 
  %let J = %scan(&amp;amp;list,&amp;amp;index); 
  have (keep=&amp;amp;J where=(&amp;amp;J ne .))
%end;
%mend;
%datasets;

data want;
length columns $8;
merge
  %datasets
;
/*I know it's not like that*/
columns = list;
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Nov 2020 11:50:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transformation-structure-of-data/m-p/697863#M213356</guid>
      <dc:creator>mazouz</dc:creator>
      <dc:date>2020-11-10T11:50:53Z</dc:date>
    </item>
    <item>
      <title>Re: Transformation structure of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transformation-structure-of-data/m-p/697866#M213359</link>
      <description>&lt;P&gt;You need to move the %LET for list into the macro, or take it out of the %LOCAL:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro datasets;
%local list index J; 
%let list = a b c d e;
%do index = 1 %to %sysfunc(countw(&amp;amp;list)); 
  %let J = %scan(&amp;amp;list,&amp;amp;index); 
  have (keep=&amp;amp;J where=(&amp;amp;J ne .))
%end;
%mend;
%datasets;

data want;
length columns $8;
merge
  %datasets
;
/*I know it's not like that*/
columns = scan("&amp;amp;list",_n_);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Nov 2020 11:57:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transformation-structure-of-data/m-p/697866#M213359</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-11-10T11:57:05Z</dc:date>
    </item>
    <item>
      <title>Re: Transformation structure of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transformation-structure-of-data/m-p/697868#M213361</link>
      <description>&lt;PRE&gt;data have;
   input a b c d e;
cards;
1 . . . .
1 . . . .
4 . . . .
5 . . . .
1 . . . .
. 2 . . .
. 1 . . .
. 2 . . .
. 3 . . .
. 4 . . .
. . 4 . .
. . 4 . .
. . 1 . .
. . 4 . .
. . 4 . .
. . . 2 .
. . . 3 .
. . . 4 .
. . . 1 .
. . . 3 .
. . . . 2
. . . . 4
. . . . 3
. . . . 2
. . . . 1
;
run;

%let dsid=%sysfunc(open(have));
%let nvar=%sysfunc(attrn(&amp;amp;dsid,nvars));
%let dsid=%sysfunc(close(&amp;amp;dsid)); 
data temp(index=(n)); 
 set have;
 n=mod(_n_,&amp;amp;nvar);
 if n=0 then n=&amp;amp;nvar;
run;
data want;
 update temp(obs=0) temp;
 by n;
run;
&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Nov 2020 12:00:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transformation-structure-of-data/m-p/697868#M213361</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-11-10T12:00:49Z</dc:date>
    </item>
    <item>
      <title>Re: Transformation structure of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transformation-structure-of-data/m-p/697872#M213364</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the code work but still have this error&lt;/P&gt;&lt;PRE&gt;NOTE: Writing TAGSETS.SASREPORT13(EGSR) Body file: EGSR
25         
26         GOPTIONS ACCESSIBLE;
27         %%macro datasets;
28         %local list index J;
29         %let list = a b c d e;
30         %do index = 1 %to %sysfunc(countw(&amp;amp;list));
31           %let J = %scan(&amp;amp;list,&amp;amp;index);
32           have (keep=&amp;amp;J where=(&amp;amp;J ne .))
33         %end;
34         %mend;
35         %datasets;
27         %%macro datasets;
           _
           180
ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Nov 2020 12:11:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transformation-structure-of-data/m-p/697872#M213364</guid>
      <dc:creator>mazouz</dc:creator>
      <dc:date>2020-11-10T12:11:16Z</dc:date>
    </item>
    <item>
      <title>Re: Transformation structure of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transformation-structure-of-data/m-p/697885#M213373</link>
      <description>&lt;P&gt;Use only one percent sign.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Nov 2020 13:11:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transformation-structure-of-data/m-p/697885#M213373</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-11-10T13:11:43Z</dc:date>
    </item>
    <item>
      <title>Re: Transformation structure of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transformation-structure-of-data/m-p/697888#M213375</link>
      <description>I try it but still same error</description>
      <pubDate>Tue, 10 Nov 2020 13:28:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transformation-structure-of-data/m-p/697888#M213375</guid>
      <dc:creator>mazouz</dc:creator>
      <dc:date>2020-11-10T13:28:53Z</dc:date>
    </item>
    <item>
      <title>Re: Transformation structure of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transformation-structure-of-data/m-p/697894#M213380</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   input a b c d e;
cards;
1 . . . .
1 . . . .
4 . . . .
5 . . . .
1 . . . .
. 2 . . .
. 1 . . .
. 2 . . .
. 3 . . .
. 4 . . .
. . 4 . .
. . 4 . .
. . 1 . .
. . 4 . .
. . 4 . .
. . . 2 .
. . . 3 .
. . . 4 .
. . . 1 .
. . . 3 .
. . . . 2
. . . . 4
. . . . 3
. . . . 2
. . . . 1
;

%let list = a b c d e;

%macro datasets(local_list);
%local index J; 
%do index = 1 %to %sysfunc(countw(&amp;amp;local_list)); 
  %let J = %scan(&amp;amp;local_list,&amp;amp;index); 
  have (keep=&amp;amp;J where=(&amp;amp;J ne .))
%end;
%mend;

data want;
length columns $8;
merge
  %datasets(&amp;amp;list)
;
columns = scan("&amp;amp;list",_n_);
run;

proc print data=want noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;columns	a	b	c	d	e
a	1	2	4	2	2
b	1	1	4	3	4
c	4	2	1	4	3
d	5	3	4	1	2
e	1	4	4	3	1
&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Nov 2020 14:12:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transformation-structure-of-data/m-p/697894#M213380</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-11-10T14:12:23Z</dc:date>
    </item>
  </channel>
</rss>

