<?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: help in my proc sql code in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/help-in-my-proc-sql-code/m-p/506303#M135702</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
options validvarname=any;
proc sql;
create table want as 
select count(distinct id) as 'TREATMENT A1'n,'Responders' as Status, 'N' as COL1 from have where trt01pn=1;
select count(distinct id) as 'TREATMENT B1'n from have where trt01pn=2;
select count(distinct id) as Total from have;

quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 21 Oct 2018 10:33:55 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2018-10-21T10:33:55Z</dc:date>
    <item>
      <title>help in my proc sql code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-in-my-proc-sql-code/m-p/506291#M135695</link>
      <description>&lt;P&gt;Dear,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need help in my code getting output needed .&amp;nbsp; With my code i am getting first three columns only. The names of column headers for TREATEMNT A1&amp;nbsp; and TREATEMNT B1, I need to have a gap between 'TREATMENT and A1'.&amp;nbsp; &amp;nbsp; &amp;nbsp; Thank you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;output needed&lt;/P&gt;
&lt;P&gt;STATUS&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; COL1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; TREATMENT A1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;TREATEMNT B1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Total&lt;/P&gt;
&lt;P&gt;Responders&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; N&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;9&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 trt01pn;
datalines;
1 1
2 2
3 1
4 2
5 1
6 2
7 1
8 1
9 2
;


proc sql;
create table want as 
select count(distinct id) as TREATMENT A1,'Responders' as Status, 'N' as COL1 from have where trt01pn=1;
select count(distinct id) as TREATMENT B1 from have where trt01pn=2;
select count(distinct id) as Total from have;

quit;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 21 Oct 2018 04:42:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-in-my-proc-sql-code/m-p/506291#M135695</guid>
      <dc:creator>knveraraju91</dc:creator>
      <dc:date>2018-10-21T04:42:43Z</dc:date>
    </item>
    <item>
      <title>Re: help in my proc sql code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-in-my-proc-sql-code/m-p/506294#M135697</link>
      <description>&lt;P&gt;What for? Reporting purposes? You should not consider such things in your actual data set.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can control such things later on in&amp;nbsp;&lt;A href="https://documentation.sas.com/?docsetId=proc&amp;amp;docsetTarget=p0bqogcics9o4xn17yvt2qjbgdpi.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_self"&gt;PROC REPORT&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 21 Oct 2018 06:13:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-in-my-proc-sql-code/m-p/506294#M135697</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-10-21T06:13:42Z</dc:date>
    </item>
    <item>
      <title>Re: help in my proc sql code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-in-my-proc-sql-code/m-p/506303#M135702</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
options validvarname=any;
proc sql;
create table want as 
select count(distinct id) as 'TREATMENT A1'n,'Responders' as Status, 'N' as COL1 from have where trt01pn=1;
select count(distinct id) as 'TREATMENT B1'n from have where trt01pn=2;
select count(distinct id) as Total from have;

quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 21 Oct 2018 10:33:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-in-my-proc-sql-code/m-p/506303#M135702</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-10-21T10:33:55Z</dc:date>
    </item>
    <item>
      <title>Re: help in my proc sql code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-in-my-proc-sql-code/m-p/506305#M135703</link>
      <description>&lt;P&gt;Thank you for the help. I am not getting the output I need. In the output I do not see Treatment B1 and Total columns. How to modify the code to get the all columns.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 21 Oct 2018 14:06:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-in-my-proc-sql-code/m-p/506305#M135703</guid>
      <dc:creator>knveraraju91</dc:creator>
      <dc:date>2018-10-21T14:06:40Z</dc:date>
    </item>
    <item>
      <title>Re: help in my proc sql code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-in-my-proc-sql-code/m-p/506307#M135705</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;below code may be helpful ..&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 distinct Status,COL1,TREATMENT_A1,TREATMENT_B1,sum(TREATMENT_A1,TREATMENT_B1) as total from(
select 'Responders' as Status, 'N' as COL1,id,trt01pn,
case when trt01pn=1 then count(*) end as TREATMENT_A1,
case when trt01pn=2 then count(*) end as TREATMENT_B1 from have group by trt01pn);
run;


proc print data=want;
sum total;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 21 Oct 2018 14:27:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-in-my-proc-sql-code/m-p/506307#M135705</guid>
      <dc:creator>singhsahab</dc:creator>
      <dc:date>2018-10-21T14:27:18Z</dc:date>
    </item>
    <item>
      <title>Re: help in my proc sql code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-in-my-proc-sql-code/m-p/506309#M135706</link>
      <description>&lt;P&gt;Hope so below Code will match your exact requirement ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Not able to copy and paste .. so posted as screen shot....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/24231i30D009CE56193369/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 21 Oct 2018 14:51:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-in-my-proc-sql-code/m-p/506309#M135706</guid>
      <dc:creator>singhsahab</dc:creator>
      <dc:date>2018-10-21T14:51:08Z</dc:date>
    </item>
    <item>
      <title>Re: help in my proc sql code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-in-my-proc-sql-code/m-p/506337#M135723</link>
      <description>Variable can’t use spaces in general. There are some ways around this, but in general it’s not recommended. Instead use labels. &lt;BR /&gt;&lt;BR /&gt;Select ... as treatment_a1 label = 'Treatment A1', &lt;BR /&gt;Rest of query. &lt;BR /&gt;&lt;BR /&gt;Then when you display the table it shows up nicely but when typing you don’t have to worry about quotes or spaces. &lt;BR /&gt;&lt;BR /&gt;The other option some have shown allow you to use a space but then you need to enclose the variable in quotes and add an n after. That’s so that SAS knows when a variable name ends. &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sun, 21 Oct 2018 22:43:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-in-my-proc-sql-code/m-p/506337#M135723</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-10-21T22:43:56Z</dc:date>
    </item>
    <item>
      <title>Re: help in my proc sql code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-in-my-proc-sql-code/m-p/506341#M135725</link>
      <description>&lt;P&gt;Formatting your long lines of code will make it much clearer why your output data set only has the values from the first SELECT.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as 
  select count(distinct id) as TREATMENT A1
       , 'Responders' as Status
       , 'N' as COL1 
  from have 
  where trt01pn=1
;

select count(distinct id) as TREATMENT B1
  from have
  where trt01pn=2
;

select count(distinct id) as Total
 from have
;

quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So your first statement is making WANT and your next two are just writing to the output window.&lt;/P&gt;
&lt;P&gt;Also your first statement is creating a variable names TREATMENT with a label of A1.&amp;nbsp; Variable names do not have spaces in them.&amp;nbsp; But you can add a label to your variable. Many procedures will display results using the label instead or or in addition to the variable name.&amp;nbsp; For example you can use the LABEL option on PROC PRINT to print the label.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Oct 2018 00:10:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-in-my-proc-sql-code/m-p/506341#M135725</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-10-22T00:10:41Z</dc:date>
    </item>
    <item>
      <title>Re: help in my proc sql code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-in-my-proc-sql-code/m-p/506408#M135759</link>
      <description>&lt;P&gt;Using the following code to check output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents data=want varnum;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;                                                                                                                   Variables in Creation Order

                                                                                                                #    Variable        Type    Len

                                                                                                                1    TREATMENT A1    Num       8
                                                                                                                2    Status          Char     10
                                                                                                                3    COL1            Char      1
&lt;/PRE&gt;</description>
      <pubDate>Mon, 22 Oct 2018 12:16:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-in-my-proc-sql-code/m-p/506408#M135759</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-10-22T12:16:39Z</dc:date>
    </item>
    <item>
      <title>Re: help in my proc sql code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-in-my-proc-sql-code/m-p/506410#M135760</link>
      <description>&lt;P&gt;I think that what you want is something like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options validvarname=any; /* needed to have blanks in variable names */
proc sql;
  create table want as select
    'Responders' as Status,
    'N' as Col1,
    (select count(distinct id) from have where trt01pn=1) as 'Treatment A1'n,
    (select count(distinct id) from have where trt01pn=2) as 'Treatment B1'n,
    count(distinct id) as Total
  from have;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 22 Oct 2018 12:22:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-in-my-proc-sql-code/m-p/506410#M135760</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2018-10-22T12:22:12Z</dc:date>
    </item>
  </channel>
</rss>

