<?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: Long to wide and show categories that are not in data set in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Long-to-wide-and-show-categories-that-are-not-in-data-set/m-p/735465#M229119</link>
    <description>&lt;P&gt;Transpose to dataset:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data RawTbl;
Input ID Code;
cards;
1 9
1 3
1 2
2 1
3 2
3 4
4 9
5 1
5 3
5 4
5 8
;

data template;
infile datalines dlm=",";
input code @@;
datalines;
1,2,3,4,5,15,20
;

data all / view=all;
set
  template
  rawtbl (where=(code in (1,2,3,4,5,15,20)))
;
run;

proc transpose
  data=all
  out=want (
    drop=_name_
    where=(id ne .)
  )
  prefix=r_
;
by id;
var code;
id code;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Since wide datasets are mostly useless, I think you want a report:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
value code
  1 = "1"
  2 = "2"
  3 = "3"
  4 = "4"
  5 = "5"
  15 = "15"
  20 = "20"
;
run;

proc report data=rawtbl (where=(code in (1,2,3,4,5,15,20)));
format code code.;
column id code=value,code;
define id / group;
define code / "" across order=data preloadfmt;
define value / "" analysis;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;ID	1	2	3	4	5	15	20
1	.	2	3	.	.	.	.
2	1	.	.	.	.	.	.
3	.	2	.	4	.	.	.
5	1	.	3	4	.	.	.
&lt;/PRE&gt;</description>
    <pubDate>Tue, 20 Apr 2021 09:38:50 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2021-04-20T09:38:50Z</dc:date>
    <item>
      <title>Long to wide and show categories that are not in data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Long-to-wide-and-show-categories-that-are-not-in-data-set/m-p/735460#M229116</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I have a data set with long structure (Each customer has multiple rows).&lt;/P&gt;
&lt;P&gt;Each customer has reasons for application to call center .&lt;/P&gt;
&lt;P&gt;The task is to re-structure the data set in the following way:&lt;/P&gt;
&lt;P&gt;1-I want to change the structure to wide.&lt;/P&gt;
&lt;P&gt;2-I want to show also reasons that are not in the raw data.&lt;/P&gt;
&lt;P&gt;I have a list of reasons that only these reasons are relevant:&amp;nbsp; 1,2,3,4,5,15,20&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the way to do it please in most effective way?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data RawTbl;
Input ID Code;
cards;
1 9
1 3
1 2
2 1
3 2
3 4
4 9
5 1
5 3
5 4
5 8
;
Run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 20 Apr 2021 09:05:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Long-to-wide-and-show-categories-that-are-not-in-data-set/m-p/735460#M229116</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-04-20T09:05:48Z</dc:date>
    </item>
    <item>
      <title>Re: Long to wide and show categories that are not in data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Long-to-wide-and-show-categories-that-are-not-in-data-set/m-p/735461#M229117</link>
      <description>&lt;P&gt;Please show the expected result using the data you have posted, making it easier to check that the description has been understood.&lt;/P&gt;
&lt;P&gt;Here is one issue, that needs to be explained&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;I have a list of reasons that only these reasons are relevant: 1,2,3,4,5,15,20&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Does this mean, that you want don't want to see any other reasons? Or do you want to see the reasons in the data plus "relevant reasons" with missing value (or zero)?&lt;/P&gt;</description>
      <pubDate>Tue, 20 Apr 2021 09:14:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Long-to-wide-and-show-categories-that-are-not-in-data-set/m-p/735461#M229117</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-04-20T09:14:42Z</dc:date>
    </item>
    <item>
      <title>Re: Long to wide and show categories that are not in data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Long-to-wide-and-show-categories-that-are-not-in-data-set/m-p/735465#M229119</link>
      <description>&lt;P&gt;Transpose to dataset:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data RawTbl;
Input ID Code;
cards;
1 9
1 3
1 2
2 1
3 2
3 4
4 9
5 1
5 3
5 4
5 8
;

data template;
infile datalines dlm=",";
input code @@;
datalines;
1,2,3,4,5,15,20
;

data all / view=all;
set
  template
  rawtbl (where=(code in (1,2,3,4,5,15,20)))
;
run;

proc transpose
  data=all
  out=want (
    drop=_name_
    where=(id ne .)
  )
  prefix=r_
;
by id;
var code;
id code;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Since wide datasets are mostly useless, I think you want a report:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
value code
  1 = "1"
  2 = "2"
  3 = "3"
  4 = "4"
  5 = "5"
  15 = "15"
  20 = "20"
;
run;

proc report data=rawtbl (where=(code in (1,2,3,4,5,15,20)));
format code code.;
column id code=value,code;
define id / group;
define code / "" across order=data preloadfmt;
define value / "" analysis;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;ID	1	2	3	4	5	15	20
1	.	2	3	.	.	.	.
2	1	.	.	.	.	.	.
3	.	2	.	4	.	.	.
5	1	.	3	4	.	.	.
&lt;/PRE&gt;</description>
      <pubDate>Tue, 20 Apr 2021 09:38:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Long-to-wide-and-show-categories-that-are-not-in-data-set/m-p/735465#M229119</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-04-20T09:38:50Z</dc:date>
    </item>
  </channel>
</rss>

