<?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: proc transpose from multiple rows to one row per customer in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-transpose-from-multiple-rows-to-one-row-per-customer/m-p/641233#M191091</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can do this for example:&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let date = %sysfunc(compress(%sysfunc(intnx(month,%sysfunc(inputn(19042020,DDMMYY10.)),-1,s),DDMMYY10.),/));

Data Have;
input  ID  Info_19042020;
cards;
999 34
999 11
888 34
777 28
;
Run;

proc transpose data=have out=_wanted1 (drop=_:) prefix=info_&amp;amp;date._C;
	var Info_19042020;
	id Info_19042020;
	by descending ID;
run;

data wanted1;
	set _wanted1;
	array _a (*) info:;
	do i=1 to dim(_a);
		if _a(i) = . then _a(i) = 0;
		else _a(i) = 1;
	end;
	drop i;
run;

proc sql noprint;
	select name into: varname separated by ","
	from dictionary.columns
	where libname="WORK" and memname="WANTED1" and find(lowcase(name),"info_")&amp;gt;0
	order by name;
run;

proc sql;
	create table wanted2 as
	select ID, &amp;amp;varname.
	from wanted1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Best,&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 20 Apr 2020 10:15:13 GMT</pubDate>
    <dc:creator>ed_sas_member</dc:creator>
    <dc:date>2020-04-20T10:15:13Z</dc:date>
    <item>
      <title>proc transpose from multiple rows to one row per customer</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-transpose-from-multiple-rows-to-one-row-per-customer/m-p/641227#M191086</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I have in the "have" data set&amp;nbsp; information of failure code for each customer in a specific date.(In this example the information is for 19 APRIL 20202 so it is written as 19042020 like DDMMYY format).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please note that a specific customer can appear in multiple rows if he had multiple failures codes.&lt;/P&gt;
&lt;P&gt;I want to change the structure of data&amp;nbsp; to one row per customer .(Please see "Wanted1 data set).&lt;/P&gt;
&lt;P&gt;Then I want to order to columns by the code (Please see "Wanted2" data set)&lt;/P&gt;
&lt;P&gt;My question is what is the code to create "Wanted1" and "Wanted2" data sets from "have " data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Have;
input  ID  Info_19042020;
cards;
999 34
999 11
888 34
777 28
;
Run;

Data Wanted1;
input  ID   info_19032020_C34  info_19032020_C11  info_19032020_C28;
cards;
999 1 1 0
888 1 0 0
777 0 0 1
;
run;


Data Wanted2;
input ID    info_19032020_C11   info_19032020_C28   info_19032020_C34;
cards;
999 1 0 1
888 0 0 1
777 0 1 0
;
run;


&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 20 Apr 2020 09:43:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-transpose-from-multiple-rows-to-one-row-per-customer/m-p/641227#M191086</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-04-20T09:43:42Z</dc:date>
    </item>
    <item>
      <title>Re: proc transpose from multiple rows to one row per customer</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-transpose-from-multiple-rows-to-one-row-per-customer/m-p/641233#M191091</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can do this for example:&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let date = %sysfunc(compress(%sysfunc(intnx(month,%sysfunc(inputn(19042020,DDMMYY10.)),-1,s),DDMMYY10.),/));

Data Have;
input  ID  Info_19042020;
cards;
999 34
999 11
888 34
777 28
;
Run;

proc transpose data=have out=_wanted1 (drop=_:) prefix=info_&amp;amp;date._C;
	var Info_19042020;
	id Info_19042020;
	by descending ID;
run;

data wanted1;
	set _wanted1;
	array _a (*) info:;
	do i=1 to dim(_a);
		if _a(i) = . then _a(i) = 0;
		else _a(i) = 1;
	end;
	drop i;
run;

proc sql noprint;
	select name into: varname separated by ","
	from dictionary.columns
	where libname="WORK" and memname="WANTED1" and find(lowcase(name),"info_")&amp;gt;0
	order by name;
run;

proc sql;
	create table wanted2 as
	select ID, &amp;amp;varname.
	from wanted1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Best,&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Apr 2020 10:15:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-transpose-from-multiple-rows-to-one-row-per-customer/m-p/641233#M191091</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-04-20T10:15:13Z</dc:date>
    </item>
    <item>
      <title>Re: proc transpose from multiple rows to one row per customer</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-transpose-from-multiple-rows-to-one-row-per-customer/m-p/641237#M191093</link>
      <description>&lt;P&gt;Like that:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Have;
input  ID  Info_19042020;
cards;
999 34
999 11
888 34
777 28
;
Run;

%let variable_name = Info_19042020;

proc sort data = Have;
  by descending ID &amp;amp;variable_name.;
run;

proc transpose data = Have out = Wanted1(drop = _NAME_) prefix=&amp;amp;variable_name._;
  by descending ID;
  id &amp;amp;variable_name.;
  var &amp;amp;variable_name.;
run;
proc print data = Wanted1;
run;

proc transpose 
  data=Wanted1(obs=0) 
  out=vars(keep = _name_ where = (_name_ like "&amp;amp;variable_name."!!'%' ));
  var _ALL_;
run;

proc sort data = vars sortseq=linguistic(NUMERIC_COLLATION = on);
  by _name_;
run;

proc sql noprint;
  select _name_ into :vars separated by " " from vars;
quit;


Data Wanted2;
  retain ID &amp;amp;vars.;
  set Wanted1;
  array V &amp;amp;vars.;
  do over V;
    V = V&amp;amp;1;
  end;
run;
proc print data = Wanted2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;all the best&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Mon, 20 Apr 2020 10:23:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-transpose-from-multiple-rows-to-one-row-per-customer/m-p/641237#M191093</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-04-20T10:23:26Z</dc:date>
    </item>
    <item>
      <title>Re: proc transpose from multiple rows to one row per customer</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-transpose-from-multiple-rows-to-one-row-per-customer/m-p/641256#M191104</link>
      <description>&lt;P&gt;Thank you.&lt;/P&gt;
&lt;P&gt;What is the target of the code when you create array?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Apr 2020 11:08:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-transpose-from-multiple-rows-to-one-row-per-customer/m-p/641256#M191104</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-04-20T11:08:14Z</dc:date>
    </item>
    <item>
      <title>Re: proc transpose from multiple rows to one row per customer</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-transpose-from-multiple-rows-to-one-row-per-customer/m-p/641258#M191105</link>
      <description>&lt;P&gt;Great great great!&lt;/P&gt;
&lt;P&gt;Can you please also explain:&lt;/P&gt;
&lt;P&gt;1-what is the target of using numeric_collation in proc sort&lt;/P&gt;
&lt;P&gt;2-what is the target of using array in last step? I understand the using of Retain in order to sort the columns by the order that we created using a macro parameter but why need also array ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Apr 2020 11:15:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-transpose-from-multiple-rows-to-one-row-per-customer/m-p/641258#M191105</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-04-20T11:15:52Z</dc:date>
    </item>
    <item>
      <title>Re: proc transpose from multiple rows to one row per customer</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-transpose-from-multiple-rows-to-one-row-per-customer/m-p/641262#M191107</link>
      <description>&lt;P&gt;@ 1)&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data x;
  x = '11'; output;
  x = '12'; output;
  x = '2'; output;
  x = '1'; output;
run;
proc print;
run;
proc sort data = x out = x1 sortseq=linguistic(NUMERIC_COLLATION = off);
  by x;
run;
proc print;
run;
proc sort data = x out = x2 sortseq=linguistic(NUMERIC_COLLATION = on);
  by x;
run;
proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;@ 2)&lt;/P&gt;
&lt;P&gt;you wanted to have 1 and 0, without the `V &amp;amp; 1` the values are "Code of error" or null.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All the best&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Mon, 20 Apr 2020 11:26:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-transpose-from-multiple-rows-to-one-row-per-customer/m-p/641262#M191107</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-04-20T11:26:09Z</dc:date>
    </item>
  </channel>
</rss>

