<?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 How to - Get Desired Data Set Output &amp;amp; Report Output By Using Data Step or Proc Sql in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Desired-Data-Set-Output-amp-Report-Output-By-Using/m-p/275247#M55017</link>
    <description>&lt;P&gt;Hello everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to ask my question to you. Again, it includes to get the data set output of some procedures. I know, SAS doesn’t let us to get the data set which has alredy had same structure with Report output but I need to create my desired output with some other methods.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a sample code as below(My real data is too big). Proc Tabulate almost can provide my desired output but I need some additional columns on my desired output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Sample Data Set;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Have;
Length Variable1 8 RankVariable 8;
Infile Datalines Missover;
Input Variable1 RankVariable;
Datalines;
0 0
1 2
0 0
1 0
0 2
1 0
1 2
1 2
0 2
;
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Here is my desired output;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/3494i8B03421237218ED2/image-size/original?v=v2&amp;amp;px=-1" border="0" alt="DesiredCAP.png" title="DesiredCAP.png" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;My first problem is to show values as zero even they don’t exist in the data set. For Example, in my sample data set there is no “1” values for "RankVariable" so “PROC TABULATE” doesn’t bring them in its report output, I also need this values as “0”.&lt;/P&gt;
&lt;P&gt;Secondly, I need to add cumulative column but this column needs to show the values being percentage values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Current Proc Tabulate Statement;&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc Tabulate Data=Have Out=Have2;
Class  RankVariable / Order=Unformatted Missing;
Class Variable1 / Order=Unformatted Missing;
Table RankVariable , Variable1;
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;I also need this report output as data set. It shouldn’t be same structure, I need the following data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Data Set Desired;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/3495iC42DADE0D084B8D6/image-size/original?v=v2&amp;amp;px=-1" border="0" alt="DesiredOutput.png" title="DesiredOutput.png" /&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Actually, this following steps could help me to create the data set but it is too manual, I think there should be more simple method to do the foreigoing demands. At this point, I would like&amp;nbsp;to get your helps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc Sql;
Create table ZeroCount AS
Select 
Count(Case When Variable1=0 And RankVariable=0 Then 0 Else . End) AS N0
,Count(Case When Variable1=0 And RankVariable=1 Then 1 Else . End) AS N1
,Count(Case When Variable1=0 And RankVariable=2 Then 2 Else . End) AS N2
From Have;
Create Table OneCount AS
Select
Count(Case When Variable1=1 And RankVariable=0 Then 0 Else . End) AS N0
,Count(Case When Variable1=1 And RankVariable=1 Then 1 Else . End) AS N1
,Count(Case When Variable1=1 And RankVariable=2 Then 2 Else . End) AS N2
From Have;
Quit;

PROC SQL;
CREATE TABLE CountTable AS 
SELECT * FROM ZEROCOUNT
OUTER UNION CORR 
SELECT * FROM ONECOUNT;
Quit;
 
 
PROC TRANSPOSE DATA=CountTable
     OUT=CountTable2
     PREFIX=Col
     NAME=Count;
     VAR N0 N1 N2;
RUN;
QUIT;
 
Data Cumulative;
Set CountTable2;
CumulativeColumn + Col2;
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Thank you&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 05 Jun 2016 13:53:36 GMT</pubDate>
    <dc:creator>turcay</dc:creator>
    <dc:date>2016-06-05T13:53:36Z</dc:date>
    <item>
      <title>How to - Get Desired Data Set Output &amp; Report Output By Using Data Step or Proc Sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Desired-Data-Set-Output-amp-Report-Output-By-Using/m-p/275247#M55017</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to ask my question to you. Again, it includes to get the data set output of some procedures. I know, SAS doesn’t let us to get the data set which has alredy had same structure with Report output but I need to create my desired output with some other methods.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a sample code as below(My real data is too big). Proc Tabulate almost can provide my desired output but I need some additional columns on my desired output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Sample Data Set;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Have;
Length Variable1 8 RankVariable 8;
Infile Datalines Missover;
Input Variable1 RankVariable;
Datalines;
0 0
1 2
0 0
1 0
0 2
1 0
1 2
1 2
0 2
;
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Here is my desired output;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/3494i8B03421237218ED2/image-size/original?v=v2&amp;amp;px=-1" border="0" alt="DesiredCAP.png" title="DesiredCAP.png" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;My first problem is to show values as zero even they don’t exist in the data set. For Example, in my sample data set there is no “1” values for "RankVariable" so “PROC TABULATE” doesn’t bring them in its report output, I also need this values as “0”.&lt;/P&gt;
&lt;P&gt;Secondly, I need to add cumulative column but this column needs to show the values being percentage values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Current Proc Tabulate Statement;&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc Tabulate Data=Have Out=Have2;
Class  RankVariable / Order=Unformatted Missing;
Class Variable1 / Order=Unformatted Missing;
Table RankVariable , Variable1;
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;I also need this report output as data set. It shouldn’t be same structure, I need the following data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Data Set Desired;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/3495iC42DADE0D084B8D6/image-size/original?v=v2&amp;amp;px=-1" border="0" alt="DesiredOutput.png" title="DesiredOutput.png" /&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Actually, this following steps could help me to create the data set but it is too manual, I think there should be more simple method to do the foreigoing demands. At this point, I would like&amp;nbsp;to get your helps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc Sql;
Create table ZeroCount AS
Select 
Count(Case When Variable1=0 And RankVariable=0 Then 0 Else . End) AS N0
,Count(Case When Variable1=0 And RankVariable=1 Then 1 Else . End) AS N1
,Count(Case When Variable1=0 And RankVariable=2 Then 2 Else . End) AS N2
From Have;
Create Table OneCount AS
Select
Count(Case When Variable1=1 And RankVariable=0 Then 0 Else . End) AS N0
,Count(Case When Variable1=1 And RankVariable=1 Then 1 Else . End) AS N1
,Count(Case When Variable1=1 And RankVariable=2 Then 2 Else . End) AS N2
From Have;
Quit;

PROC SQL;
CREATE TABLE CountTable AS 
SELECT * FROM ZEROCOUNT
OUTER UNION CORR 
SELECT * FROM ONECOUNT;
Quit;
 
 
PROC TRANSPOSE DATA=CountTable
     OUT=CountTable2
     PREFIX=Col
     NAME=Count;
     VAR N0 N1 N2;
RUN;
QUIT;
 
Data Cumulative;
Set CountTable2;
CumulativeColumn + Col2;
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Thank you&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Jun 2016 13:53:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Desired-Data-Set-Output-amp-Report-Output-By-Using/m-p/275247#M55017</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2016-06-05T13:53:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Get Desired Data Set Output &amp; Report Output By Using Data Step or Proc Sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Desired-Data-Set-Output-amp-Report-Output-By-Using/m-p/275249#M55019</link>
      <description>Hi:&lt;BR /&gt;  Have you looked into the use of PRELOADFMT with PROC TABULATE? You will need a user-defined format, but then you can show all possible categories even when the category is not present in the data. There are examples in the doc for how to use PRELOADFMT.&lt;BR /&gt;cynthia</description>
      <pubDate>Sun, 05 Jun 2016 15:49:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Desired-Data-Set-Output-amp-Report-Output-By-Using/m-p/275249#M55019</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2016-06-05T15:49:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Get Desired Data Set Output &amp; Report Output By Using Data Step or Proc Sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Desired-Data-Set-Output-amp-Report-Output-By-Using/m-p/275250#M55020</link>
      <description>Hi:&lt;BR /&gt;  It seems like this question is related to this previous post: &lt;A href="https://communities.sas.com/t5/Base-SAS-Programming/Get-Number-of-Zero-Values-and-Get-Percentage-of-Zero-Values/m-p/273941/highlight/true#M54600" target="_blank"&gt;https://communities.sas.com/t5/Base-SAS-Programming/Get-Number-of-Zero-Values-and-Get-Percentage-of-Zero-Values/m-p/273941/highlight/true#M54600&lt;/A&gt; &lt;BR /&gt;&lt;BR /&gt;was there something about that post that has changed since you marked it as solved?&lt;BR /&gt;&lt;BR /&gt;cynthia</description>
      <pubDate>Sun, 05 Jun 2016 15:58:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Desired-Data-Set-Output-amp-Report-Output-By-Using/m-p/275250#M55020</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2016-06-05T15:58:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Get Desired Data Set Output &amp; Report Output By Using Data Step or Proc Sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Desired-Data-Set-Output-amp-Report-Output-By-Using/m-p/275252#M55022</link>
      <description>&lt;P&gt;Hello Cynthia,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;After you mentioned the PRELOADFMT in your previous post&amp;nbsp;, I remembered and checked my previous question which you shared with me as above. Now, I'm checking that post to reach my aim.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Actually, because I used Reeza's code, I didn't investigate&amp;nbsp;&lt;SPAN&gt;PRELOADFMT sample deeply. I'm looking your sample&amp;nbsp;PRELOADFMT code then I will try to create my desired output report and data set by using&amp;nbsp;PRELOADFMT.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thank you,&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Jun 2016 16:08:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Desired-Data-Set-Output-amp-Report-Output-By-Using/m-p/275252#M55022</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2016-06-05T16:08:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Get Desired Data Set Output &amp; Report Output By Using Data Step or Proc Sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Desired-Data-Set-Output-amp-Report-Output-By-Using/m-p/275287#M55032</link>
      <description>&lt;P&gt;It is more suitable for PROC REPORT. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;PROC TABULATE don't have statistical like CUMPCT.&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;
Length Variable1 8 RankVariable 8;
Infile Datalines Missover;
Input Variable1 RankVariable;
Datalines;
0 0
1 2
0 0
1 0
0 2
1 0
1 2
1 2
0 2
;
Run;

proc format;
value fmt
 0='0'
 1='1'
 2='2';
run;


proc report data=have nowd completerows ;
columns RankVariable Variable1 CumulativePercent ;
define RankVariable/group format=fmt. preloadfmt;
define Variable1 /across;
define CumulativePercent /computed format=percent8.2;
compute before;
 cumpct=0;
 sum=sum(_c2_,_c3_);
endcomp;
compute CumulativePercent ;
 cumpct+sum(_c2_,_c3_)/sum;
 CumulativePercent=cumpct;
endcomp;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/3503i75D53A3D2173215C/image-size/original?v=v2&amp;amp;px=-1" border="0" alt="x.png" title="x.png" /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jun 2016 02:43:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Desired-Data-Set-Output-amp-Report-Output-By-Using/m-p/275287#M55032</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-06-06T02:43:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Get Desired Data Set Output &amp; Report Output By Using Data Step or Proc Sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Desired-Data-Set-Output-amp-Report-Output-By-Using/m-p/275310#M55038</link>
      <description>&lt;P&gt;Xia,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you very much for providing foregoing code &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But is %44.44 right? shouldn't be it %40.00 instead of %44.44? I'm not sure.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you,&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jun 2016 07:26:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Desired-Data-Set-Output-amp-Report-Output-By-Using/m-p/275310#M55038</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2016-06-06T07:26:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Get Desired Data Set Output &amp; Report Output By Using Data Step or Proc Sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Desired-Data-Set-Output-amp-Report-Output-By-Using/m-p/275312#M55039</link>
      <description>But you only have 9 obs , right ?</description>
      <pubDate>Mon, 06 Jun 2016 07:48:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Desired-Data-Set-Output-amp-Report-Output-By-Using/m-p/275312#M55039</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-06-06T07:48:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Get Desired Data Set Output &amp; Report Output By Using Data Step or Proc Sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Desired-Data-Set-Output-amp-Report-Output-By-Using/m-p/275316#M55041</link>
      <description>&lt;P&gt;Xia,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For this sample data set, yes. But in my real data set, I have 80.000 obs and it seems to me it takes to much time, I'm still waiting.&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, 06 Jun 2016 08:02:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Desired-Data-Set-Output-amp-Report-Output-By-Using/m-p/275316#M55041</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2016-06-06T08:02:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Get Desired Data Set Output &amp; Report Output By Using Data Step or Proc Sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Desired-Data-Set-Output-amp-Report-Output-By-Using/m-p/275318#M55043</link>
      <description>&lt;P&gt;This could get you a little faster .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Have;
Length Variable1 8 RankVariable 8;
Infile Datalines Missover;
Input Variable1 RankVariable;
Datalines;
0 0
1 2
0 0
1 0
0 2
1 0
1 2
1 2
0 2
;
Run;

proc format;
value fmt
 0='0'
 1='1'
 2='2';
run;

%let dsid=%sysfunc(open(have));
%let nobs=%sysfunc(attrn(&amp;amp;dsid,nlobs));
%let dsid=%sysfunc(close(&amp;amp;dsid));

proc report data=have nowd completerows ;
columns RankVariable Variable1 CumulativePercent ;
define RankVariable/group format=fmt. preloadfmt;
define Variable1 /across;
define CumulativePercent /computed format=percent8.2;
compute CumulativePercent ;
 cumpct+sum(_c2_,_c3_)/&amp;amp;nobs;
 CumulativePercent=cumpct;
endcomp;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 Jun 2016 08:11:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Desired-Data-Set-Output-amp-Report-Output-By-Using/m-p/275318#M55043</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-06-06T08:11:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Get Desired Data Set Output &amp; Report Output By Using Data Step or Proc Sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Desired-Data-Set-Output-amp-Report-Output-By-Using/m-p/275331#M55048</link>
      <description>&lt;P&gt;Xia,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you very much for your attention and providing this code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But it seems that it takes too much time for 80.000 obs. I think for 80.000 obs, it can be better to do the calculation outside of PROC REPORT. What do you think?&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, 06 Jun 2016 09:24:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Desired-Data-Set-Output-amp-Report-Output-By-Using/m-p/275331#M55048</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2016-06-06T09:24:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Get Desired Data Set Output &amp; Report Output By Using Data Step or Proc Sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Desired-Data-Set-Output-amp-Report-Output-By-Using/m-p/275537#M55097</link>
      <description>&lt;P&gt;Cynthia,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Am I writing syntax incorrect?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
value fmt
 0="0"
 1="1"
 2="2";
run;
Proc Tabulate Data=Have Missing Out=Have2;
Class  RankVariable Variable1 / Preloadfmt ;
Table RankVariable , Variable1 / Printmiss;
Format RankVariable Variable1 $fmt.;
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jun 2016 23:15:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Desired-Data-Set-Output-amp-Report-Output-By-Using/m-p/275537#M55097</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2016-06-06T23:15:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Get Desired Data Set Output &amp; Report Output By Using Data Step or Proc Sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Desired-Data-Set-Output-amp-Report-Output-By-Using/m-p/275542#M55099</link>
      <description>&lt;P&gt;Sure.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Have;
Length Variable1 8 RankVariable 8;
Infile Datalines Missover;
Input Variable1 RankVariable;
Datalines;
0 0
1 2
0 0
1 0
0 2
1 0
1 2
1 2
0 2
;
Run;

data level;
RankVariable=0;output;
RankVariable=1;output;
RankVariable=2;output;
run;

proc sql noprint;
select count(*) into : nobs from have;

create table temp as
select b.RankVariable,a.Variable1 
 from have as a full join level as b on
  a.RankVariable=b.RankVariable;
  
create table want as
select RankVariable,sum(Variable1=0) as Variable1_0 label='0',
                    sum(Variable1=1) as Variable1_1 label='1'
 from temp
  group by RankVariable;
quit;
data want;
 set want ;
 CumulativePercent+(Variable1_0+Variable1_1)/&amp;amp;nobs;
 format CumulativePercent percent8.2;
run;
proc report data=want nowd;
columns RankVariable ('Variable1' Variable1_0 Variable1_1) CumulativePercent ;
define RankVariable /display;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Jun 2016 01:04:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Desired-Data-Set-Output-amp-Report-Output-By-Using/m-p/275542#M55099</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-06-07T01:04:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Get Desired Data Set Output &amp; Report Output By Using Data Step or Proc Sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Desired-Data-Set-Output-amp-Report-Output-By-Using/m-p/275624#M55131</link>
      <description>&lt;P&gt;Thank you very much Xia,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your sample code helped me so much, however I still didn't reach my desired output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let's say that my RankVariable has 10 values, to create my desired output, I modified your sample data as below . It is almost done. In the percentage column, I need to add one additional thing to reach my goal.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Level;
RankVariable =0;Output;
RankVariable =1;Output;
RankVariable =2;Output;
RankVariable =3;Output;
RankVariable =4;Output;
RankVariable =5;Output;
RankVariable =6;Output;
RankVariable =7;Output;
RankVariable =8;Output;
RankVariable =9;Output;
RankVariable =10;Output;
Run;
 
Proc Sql Noprint;
Select Count(*) Into : Nobs From Have;
 
Create Table Want As
Select B.RankVariable 
,Sum(Variable1=0) As Variable1_0 Label='0'
,Sum(Variable1=1) As Variable1_1 Label='1'
From Have As A
Full Join Level As B
On A.RankVariable =B.RankVariable 
Group By B.RankVariable ;
Quit;
Data Want2;
Set Want;
Variable1_0=Lag(Variable1_0);
Variable1_1=Lag(Variable1_1);
If Variable1_0=. Then Variable1_0=0;
If Variable1_1=. Then Variable1_1=0;
Run;

Data Want3;
Set Want2 ;
CumulativePercent+Variable1_1/&amp;amp;Nobs;
Format CumulativePercent Percent8.2;
Run;
 
 
Proc Report Data=Want2 Nowd;
Columns RankVariable  ('Variable1_1' Variable1_0 Variable1_1) CumulativePercent ;
Define RankVariable  / Display;
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My current report output,&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/3518i44C9E3E072402E47/image-size/original?v=v2&amp;amp;px=-1" border="0" alt="Current.png" title="Current.png" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Desired Report;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/3519iA6917DBBB13E869C/image-size/original?v=v2&amp;amp;px=-1" border="0" alt="Desired.png" title="Desired.png" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS: I need to get cumulative percentage values just for NPL_F_1, it is "Variable1_1" in my sample data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can somebody still help me?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jun 2016 11:32:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Desired-Data-Set-Output-amp-Report-Output-By-Using/m-p/275624#M55131</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2016-06-07T11:32:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Get Desired Data Set Output &amp; Report Output By Using Data Step or Proc Sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Desired-Data-Set-Output-amp-Report-Output-By-Using/m-p/275657#M55139</link>
      <description>Hi:&lt;BR /&gt;  Since you are creating the Cumulative Percent yourself, you have 2 choices: multiply by 100 in the DATA step where you calculate Cumulative Percent OR do it in PROC REPORT. What is your DEFINE statement for the CumulativePercentage variable. The SAS PERCENT format does an automatic multiply by 100, why not try that? Or, just multiply by 100 in the DATA step if you don't want a Percent sign.&lt;BR /&gt;&lt;BR /&gt;cynthia</description>
      <pubDate>Tue, 07 Jun 2016 13:30:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Desired-Data-Set-Output-amp-Report-Output-By-Using/m-p/275657#M55139</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2016-06-07T13:30:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Get Desired Data Set Output &amp; Report Output By Using Data Step or Proc Sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Desired-Data-Set-Output-amp-Report-Output-By-Using/m-p/275669#M55144</link>
      <description>&lt;P&gt;Thank you Cynthia,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I have two choices,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can do it in Data step or I can do it in Proc Report.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Actually, Xia prepared codes for both Data Step and Proc Report statements.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Because I have 80.000 obs in my real Data Set, it takes to much time when we use Proc Report statement. So I decided to create in Data Set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Xia's code seems correct, but there are some diferences between Excel and SAS output. I think the following step needs to change. I multiplied with 100, but it didn't seem correct. I need to make some changes on Cumulative percentage step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Want3;
Set Want2 ;
CumulativePercent+Variable1_1/&amp;amp;Nobs;
Format CumulativePercent Percent8.2;
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I also tried to use PRELOADFMT. in my one of the previos post, but I got an error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm sorry, I'm little bit confused &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt; I'm going to make some search more detailed. Let me check again.&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jun 2016 13:58:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Desired-Data-Set-Output-amp-Report-Output-By-Using/m-p/275669#M55144</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2016-06-07T13:58:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Get Desired Data Set Output &amp; Report Output By Using Data Step or Proc Sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Desired-Data-Set-Output-amp-Report-Output-By-Using/m-p/275671#M55146</link>
      <description>&lt;P&gt;Actually, what I try to say&amp;nbsp;that, in my foregoing Desired and Current output, &amp;nbsp;in both image NPL_F_1 values same, why CumuluativePercent comes as different. I just didn't understand.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you,&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jun 2016 14:04:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Desired-Data-Set-Output-amp-Report-Output-By-Using/m-p/275671#M55146</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2016-06-07T14:04:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Get Desired Data Set Output &amp; Report Output By Using Data Step or Proc Sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Desired-Data-Set-Output-amp-Report-Output-By-Using/m-p/275739#M55184</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp﻿&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The following code creates my desired output but I made so much Data Step, shouldn't be different method to get same result?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*For Ranking*/
Data Level;
RankVariable =0;Output;
RankVariable =1;Output;
RankVariable =2;Output;
RankVariable =3;Output;
RankVariable =4;Output;
RankVariable =5;Output;
RankVariable =6;Output;
RankVariable =7;Output;
RankVariable =8;Output;
RankVariable =9;Output;
RankVariable =10;Output;
Run;
 /*Ranking*/
Proc Sql ;
Create Table Want As
Select B.RankVariable 
,Sum(Variable1=0) As Variable1_0 Label='0'
,Sum(Variable1=1) As Variable1_1 Label='1'
From Have As A
Full Join Level As B
On A.RankVariable =B.RankVariable 
Group By B.RankVariable ;
Quit;
/*Lagging for proper data set*/
Data Want2;
Set Want;
Variable1_0=Lag(Variable1_0);
Variable1_1=Lag(Variable1_1);
If Variable1_0=. Then Variable1_0=0;
If Variable1_1=. Then Variable1_1=0;
Run;
/*Creating Cumulative Column*/
Data Want3;
Set Want2 ;
Cumulative+Variable1_1;
Run;
/*Get Total Value*/
PROC SQL;
Create Table Want4 As
Select *,Sum(Variable1_1) AS Total
From Want3 ;
QUIT;
/*Cumulative column divide Total column desired result*/
Data Want5;
Set Want4;
CumulativePercent=(Cumulative/Total);
Format CumulativePercent Percent8.2;
Run;
/*Reporting*/ 
Proc Report Data=Want5 Nowd;
Columns Rank_P_NPL_F1 ('NPL_F_1' Variable1_0 Variable1_1) CumulativePercent ;
Define Rank_P_NPL_F1 / Display;
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jun 2016 16:38:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Desired-Data-Set-Output-amp-Report-Output-By-Using/m-p/275739#M55184</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2016-06-07T16:38:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Get Desired Data Set Output &amp; Report Output By Using Data Step or Proc Sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Desired-Data-Set-Output-amp-Report-Output-By-Using/m-p/275827#M55216</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The following code is the best which I could do it. It provides my desired output but I'm not sure whether this method is correct or not.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also I'm still can't get it the PRELOADFMT, even though, I put the statement in my Define option, I cannot see the zero values &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*PROC RANK DATA = BeforeHave DESCENDING GROUPS=3 TIES=MEAN OUT=Have;
VAR Variable2; 
RANKS RankVariable ;
RUN;
QUIT;*/

Data Have;
Length Variable1 8 RankVariable 8;
Infile Datalines Missover;
Input Variable1 RankVariable;
Datalines;
0 0
1 2
0 0
1 0
0 2
1 0
1 2
1 2
0 2
;
Run;

Proc Sql ;
Create Table Want As
Select Data1.*, Sum(Data1.Variable1_1) As Total From
(Select RankVariable
,Sum(Variable1=0) As Variable1_0 Label='0'
,Sum(Variable1=1) As Variable1_1 Label='1'
From Have
Group By RankVariable) AS Data1;
Quit;

Data Want2;
Set Want;
Lag_Variable1_0=Lag(Variable1_0);
Lag_Variable1_1=Lag(Variable1_1);
If Lag_Variable1_0=. Then Lag_Variable1_0=0;
If Lag_Variable1_1=. Then Lag_Variable1_1=0;
Cumulative+Variable1_1;
CumulativePercent=(Cumulative/Total);
Run;
proc format;
value fmt
 0='0'
 1='1'
 2='2';
run;
Proc Report Data=Want2 Nowd;
Columns RankVariable ('NPL_F_1' Lag_Variable1_0 Lag_Variable1_1) CumulativePercent ;
Define RankVariable/ Group Format=Fmt. Preloadfmt;
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jun 2016 22:40:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Desired-Data-Set-Output-amp-Report-Output-By-Using/m-p/275827#M55216</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2016-06-07T22:40:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Get Desired Data Set Output &amp; Report Output By Using Data Step or Proc Sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Desired-Data-Set-Output-amp-Report-Output-By-Using/m-p/275841#M55221</link>
      <description>&lt;P&gt;Yes. You are right .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just Change &lt;BR /&gt; CumulativePercent+(Variable1_0+Variable1_1)/&amp;amp;nobs;&lt;BR /&gt;into &lt;BR /&gt; CumulativePercent+ Variable1_1/&amp;amp;nobs;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;AND&lt;BR /&gt;Change SQL&lt;BR /&gt; select count(*) into : nobs from have&lt;/P&gt;
&lt;P&gt;into&lt;/P&gt;
&lt;P&gt;select count(*) into : nobs from have &lt;BR /&gt; where Variable1=1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;OR PROC TABULATE+PROC REPORT&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Have;
Length Variable1 8 RankVariable 8;
Infile Datalines Missover;
Input Variable1 RankVariable;
Datalines;
0 0
1 2
0 0
1 0
0 2
1 0
1 2
1 2
0 2
;
Run;
proc format;
value fmt
 0="0"
 1="1"
 2="2";
run;
Proc Tabulate Data=Have  Out=Have2 ;
Class  RankVariable  / Preloadfmt ;
Class Variable1;
Table RankVariable,Variable1 / Printmiss misstext='0';
Format RankVariable fmt.;
Run;
proc sql noprint;
 select count(*) into : nobs from have 
  where Variable1=1;
quit;
options missing='0';
proc report data=have2 nowd ;
columns RankVariable n,Variable1 cum_pct;
define RankVariable/group;
define Variable1/across;
define n/analysis ' ';
define cum_pct/computed format=percent8.2;
compute cum_pct;
 temp+_c3_/&amp;amp;nobs ;
 cum_pct+temp;
endcomp;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/3527i03E96EC3A80D3AFC/image-size/original?v=v2&amp;amp;px=-1" border="0" alt="x.png" title="x.png" /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jun 2016 01:56:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Desired-Data-Set-Output-amp-Report-Output-By-Using/m-p/275841#M55221</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-06-08T01:56:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to - Get Desired Data Set Output &amp; Report Output By Using Data Step or Proc Sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Desired-Data-Set-Output-amp-Report-Output-By-Using/m-p/275919#M55248</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp﻿&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;After I did the changes it worked successfully. Thank you very much.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For your PROC REPORT code, it also worked fine but as I said before, it takes too much time for 80.000 observations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I also want to ask one more question, in my following code, how can I bring the "0" values in my output?_&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc Sql ;
Create Table Want As
Select Data1.*, Sum(Data1.Variable1_1) As Total From
(Select RankVariable
,Sum(Variable1=0) As Variable1_0 Label='0'
,Sum(Variable1=1) As Variable1_1 Label='1'
From Have
Group By RankVariable) AS Data1;
Quit;

Data Want2;
Set Want;
Lag_Variable1_0=Lag(Variable1_0);
Lag_Variable1_1=Lag(Variable1_1);
If Lag_Variable1_0=. Then Lag_Variable1_0=0;
If Lag_Variable1_1=. Then Lag_Variable1_1=0;
Cumulative+Variable1_1;
CumulativePercent=(Cumulative/Total);
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jun 2016 10:22:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Desired-Data-Set-Output-amp-Report-Output-By-Using/m-p/275919#M55248</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2016-06-08T10:22:31Z</dc:date>
    </item>
  </channel>
</rss>

