<?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: Include a condition in proc sql to evaluate if the variable exists in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Include-a-condition-in-proc-sql-to-evaluate-if-the-variable/m-p/881766#M348430</link>
    <description>&lt;P&gt;This could be a lot of typing depending on your real situation, but it works. It uses the %EXPANDVARLIST macro at&amp;nbsp;&lt;A href="https://support.sas.com/resources/papers/proceedings13/032-2013.pdf" target="_blank" rel="noopener"&gt;https://support.sas.com/resources/papers/proceedings13/032-2013.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let varnames=%expandvarlist(data=sashelp.class);
%put &amp;amp;=varnames;

proc sql;
    create table def as select
        name
        ,sex
        ,age
        %if %sysfunc(findw(%upcase(&amp;amp;varnames),HEIGHT))&amp;gt;0 %then %do; ,height %end;
        %if %sysfunc(findw(%upcase(&amp;amp;varnames),CAULIFLOWER))&amp;gt;0 %then %do; ,cauliflower %end;
    from sashelp.class;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 21 Jun 2023 19:11:46 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2023-06-21T19:11:46Z</dc:date>
    <item>
      <title>Include a condition in proc sql to evaluate if the variable exists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Include-a-condition-in-proc-sql-to-evaluate-if-the-variable/m-p/881745#M348416</link>
      <description>&lt;P&gt;The following datasets are two examples. The proc sql determines whether there is a value or nor under each variable starting with time_. My problem is that we have lots of datasets to evaluate and 20 variables as time_.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data ds1;
input ID	pair	type	time_3	time_6	time_9	time_18;
datalines;
1	1	a	111	134	. 	.		
2	1	b	110	.	123	.	
3	2	a	.	131	.	120
4	2	b	.      .	.	123;
run;


data ds2;
input ID	pair	type	time_3	time_9	time_15;
datalines;
1	1	a	111	134	. 		
2	1	b	110	.	123	
3	2	a	.	131	.
4	2	b	125     .	.;
run;

proc sql;
create table counts as
select ID, pair, type,
not missing (time_3) as time_3,
not missing (time_6) as time_6,
not missing (time_9) as time_9,
not missing (time_18) as time_18
from ds1;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The way proc sql is now coded, you can only include the variables available in the dataset of interest (in the above proc sql is for ds1). Is there a way to include a condition that will only run the statement "not missing..." if the variable exists? This way we can include all possible variables starting with time_ at once. Like the following (which include time_12 and time_15 not available in ds1):&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc sql;
create table counts as
select ID, pair, type,
not missing (time_3) as time_3,
not missing (time_6) as time_6,
not missing (time_9) as time_9,
not missing (time_12) as time_12,
not missing (time_15) as time_15,
not missing (time_18) as time_18
from ds1;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 21 Jun 2023 16:28:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Include-a-condition-in-proc-sql-to-evaluate-if-the-variable/m-p/881745#M348416</guid>
      <dc:creator>ANKH1</dc:creator>
      <dc:date>2023-06-21T16:28:38Z</dc:date>
    </item>
    <item>
      <title>Re: Include a condition in proc sql to evaluate if the variable exists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Include-a-condition-in-proc-sql-to-evaluate-if-the-variable/m-p/881750#M348419</link>
      <description>&lt;P&gt;You could use macro logic to get the list of variables in advance.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ds1;
input ID	pair	type $	time_3	time_6	time_9	time_18;
datalines;
1	1	a	111	134	. 	.		
2	1	b	110	.	123	.	
3	2	a	.	131	.	120
4	2	b	.      .	.	123
;
run;


data ds2;
input ID	pair	type $	time_3	time_9	time_15;
datalines;
1	1	a	111	134	. 		
2	1	b	110	.	123	
3	2	a	.	131	.
4	2	b	125     .	.
;
run;

%macro check(dsn);
proc sql noprint;
select name into :varlist separated by ' '
from dictionary.columns 
where libname="WORK" and memname="%upcase(&amp;amp;dsn)"
 and upcase(name) like "TIME_%";
quit;
%put &amp;amp;varlist;
%let num=%sysfunc(countw(&amp;amp;varlist,%str( )));
%put &amp;amp;num;

proc sql;
create table counts as
select ID, pair, type,
%do i=1 %to &amp;amp;num;
 %if &amp;amp;i ne &amp;amp;num %then %do;
not missing (%scan(&amp;amp;varlist,&amp;amp;i,%str( )) ) as %scan(&amp;amp;varlist,&amp;amp;i,%str( )),
%end;
%else %do;
not missing (%scan(&amp;amp;varlist,&amp;amp;i,%str( )) ) as %scan(&amp;amp;varlist,&amp;amp;i,%str( ))
%end;
%end;
from &amp;amp;dsn;
quit;
%mend;

options mprint mlogic symbolgen;
%check(ds2)
proc print data=counts;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 21 Jun 2023 16:53:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Include-a-condition-in-proc-sql-to-evaluate-if-the-variable/m-p/881750#M348419</guid>
      <dc:creator>Kathryn_SAS</dc:creator>
      <dc:date>2023-06-21T16:53:45Z</dc:date>
    </item>
    <item>
      <title>Re: Include a condition in proc sql to evaluate if the variable exists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Include-a-condition-in-proc-sql-to-evaluate-if-the-variable/m-p/881763#M348429</link>
      <description>&lt;P&gt;I think that you need to show what you expect the output to look like.&lt;/P&gt;
&lt;P&gt;Perhaps you want a data step and array processing as you can write code that doesn't know all of the variables.&lt;/P&gt;
&lt;P&gt;The : builds a list of variables in a data step of all variables that start with that text. So you can use time_: to indicate that all of those variables with the variable names get used in the array to process. Lists and arrays however are not available in SQL.&lt;/P&gt;
&lt;PRE&gt;data ds1;
input ID	pair	type $	time_3	time_6	time_9	time_18;
datalines;
1	1	a	111	134	. 	.		
2	1	b	110	.	123	.	
3	2	a	.	131	.	120
4	2	b	.      .	.	123
;
run;

data want;
   set ds1;
   array t (*) time_: ;
   do i=1 to dim(t);
      t[i]= not missing(t[i]);
   end;
   drop i;
run;&lt;/PRE&gt;
&lt;P&gt;Note: you should test your data step before posting. The variable Type should be character, otherwise you get all missing values due to type error. Also, the line that has a semicolon ends the datalines block. So your step doesn't have the values from the last line of data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Jun 2023 18:42:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Include-a-condition-in-proc-sql-to-evaluate-if-the-variable/m-p/881763#M348429</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-06-21T18:42:54Z</dc:date>
    </item>
    <item>
      <title>Re: Include a condition in proc sql to evaluate if the variable exists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Include-a-condition-in-proc-sql-to-evaluate-if-the-variable/m-p/881766#M348430</link>
      <description>&lt;P&gt;This could be a lot of typing depending on your real situation, but it works. It uses the %EXPANDVARLIST macro at&amp;nbsp;&lt;A href="https://support.sas.com/resources/papers/proceedings13/032-2013.pdf" target="_blank" rel="noopener"&gt;https://support.sas.com/resources/papers/proceedings13/032-2013.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let varnames=%expandvarlist(data=sashelp.class);
%put &amp;amp;=varnames;

proc sql;
    create table def as select
        name
        ,sex
        ,age
        %if %sysfunc(findw(%upcase(&amp;amp;varnames),HEIGHT))&amp;gt;0 %then %do; ,height %end;
        %if %sysfunc(findw(%upcase(&amp;amp;varnames),CAULIFLOWER))&amp;gt;0 %then %do; ,cauliflower %end;
    from sashelp.class;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 21 Jun 2023 19:11:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Include-a-condition-in-proc-sql-to-evaluate-if-the-variable/m-p/881766#M348430</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-06-21T19:11:46Z</dc:date>
    </item>
    <item>
      <title>Re: Include a condition in proc sql to evaluate if the variable exists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Include-a-condition-in-proc-sql-to-evaluate-if-the-variable/m-p/881768#M348431</link>
      <description>&lt;P&gt;Sorry, I thought it would be easier to ask my questions in part, but you are right. It is best to show what final output I am looking for.&lt;/P&gt;&lt;P&gt;Having the sample dataset in the form of table:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;pair&lt;/TD&gt;&lt;TD&gt;type&lt;/TD&gt;&lt;TD&gt;time_3&lt;/TD&gt;&lt;TD&gt;time_6&lt;/TD&gt;&lt;TD&gt;time_9&lt;/TD&gt;&lt;TD&gt;time_12&lt;/TD&gt;&lt;TD&gt;time_18&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;a&lt;/TD&gt;&lt;TD&gt;111&lt;/TD&gt;&lt;TD&gt;134&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;b&lt;/TD&gt;&lt;TD&gt;110&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;123&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;a&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;131&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;102&lt;/TD&gt;&lt;TD&gt;120&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;b&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;121&lt;/TD&gt;&lt;TD&gt;123&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We need a table with columns (Type_a and Type_b) that adds by type per time_ how many cells with not missing values they are. Second, we need a column that shows per pair, how many pairs have values for each time_. This should be the output in a table:&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;time&lt;/TD&gt;&lt;TD&gt;Type_a&lt;/TD&gt;&lt;TD&gt;Type_b&lt;/TD&gt;&lt;TD&gt;pair&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;time_3&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;time_6&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;time_9&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;time_12&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;time_18&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Wed, 21 Jun 2023 19:17:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Include-a-condition-in-proc-sql-to-evaluate-if-the-variable/m-p/881768#M348431</guid>
      <dc:creator>ANKH1</dc:creator>
      <dc:date>2023-06-21T19:17:53Z</dc:date>
    </item>
    <item>
      <title>Re: Include a condition in proc sql to evaluate if the variable exists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Include-a-condition-in-proc-sql-to-evaluate-if-the-variable/m-p/881770#M348432</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Why would you use SQL to do it?&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Normal SAS code is usually much easier to write.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ds1;
  input ID pair type $ time_3 time_6 time_9 time_18;
datalines;
1 1 a 111 134   .   .  
2 1 b 110   . 123   . 
3 2 a   . 131   . 120
4 2 b   .   .   . 123
;

data counts;
  set ds1;
  array t time_:;
  do over t;
     t=not missing(t);
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;Obs    ID    pair    type    time_3    time_6    time_9    time_18

 1      1      1      a         1         1         0         0
 2      2      1      b         1         0         1         0
 3      3      2      a         0         1         0         1
 4      4      2      b         0         0         0         1
&lt;/PRE&gt;
&lt;P&gt;What is it you are actually trying to do here?&amp;nbsp; That doesn't look much like "COUNTS".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you just want to bin the values in missing or non-missing why not use a format?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format ;
  value miss low-high='Missing' other='Non-Missing';
run;
proc freq data=ds1;
  tables time: / missing;
  format time: miss.;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1687375100061.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/85205i75EBBBC2E40CCC72/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1687375100061.png" alt="Tom_0-1687375100061.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Jun 2023 19:18:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Include-a-condition-in-proc-sql-to-evaluate-if-the-variable/m-p/881770#M348432</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-06-21T19:18:26Z</dc:date>
    </item>
    <item>
      <title>Re: Include a condition in proc sql to evaluate if the variable exists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Include-a-condition-in-proc-sql-to-evaluate-if-the-variable/m-p/881792#M348434</link>
      <description>&lt;P&gt;I cannot see how you got the second dataset from the first one.&amp;nbsp; What is PAIR counting in the second dataset? It does not seem to have anything to do with the PAIR in the first dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It really looks like your data should be organized as PAIR, TYPE, TIME, VALUE instead.&amp;nbsp; Then the dataset structure is fixed no matter how many times or types there are.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or possibly if the TYPE is always A or B and you want the A and B rows to be PAIRED then perhaps you have PAIR, TIME and VALUE_A and VALUE_B&amp;nbsp; instead?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Jun 2023 19:31:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Include-a-condition-in-proc-sql-to-evaluate-if-the-variable/m-p/881792#M348434</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-06-21T19:31:09Z</dc:date>
    </item>
    <item>
      <title>Re: Include a condition in proc sql to evaluate if the variable exists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Include-a-condition-in-proc-sql-to-evaluate-if-the-variable/m-p/881798#M348436</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I apologize.&amp;nbsp;Each ID belongs to a unique pair (this dataset only shows 1 and 2, but the number of pairs is greater in the larger dataset) and a type (either a or b). Per each pair, you have one type=a and one type=b. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;First, we want to count how many rows we have per type (a and b) with values. Hence, columns Type_a and Type_b. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Column pair, derives from counting how many pairs (each pair composed of two IDS) BOTH IDs have values per time_.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Jun 2023 20:00:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Include-a-condition-in-proc-sql-to-evaluate-if-the-variable/m-p/881798#M348436</guid>
      <dc:creator>ANKH1</dc:creator>
      <dc:date>2023-06-21T20:00:25Z</dc:date>
    </item>
    <item>
      <title>Re: Include a condition in proc sql to evaluate if the variable exists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Include-a-condition-in-proc-sql-to-evaluate-if-the-variable/m-p/881805#M348439</link>
      <description>&lt;P&gt;So if you know the data has two observations per pair then you can probably get it done by adding a PROC TRANSPOSE step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ds1;
  input ID pair type $ time_3 time_6 time_9 time_18;
datalines;
1 1 a 111 134   .   .  
2 1 b 110   . 123   . 
3 2 a   . 131   . 120
4 2 b   .   .   . 123
;

proc transpose data=ds1 out=ds1T name=time prefix=type_;
  by pair ;
  id type;
  var time_: ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you have data like this:&lt;/P&gt;
&lt;PRE&gt;Obs    pair     time      type_a    type_b

 1       1     time_3       111       110
 2       1     time_6       134         .
 3       1     time_9         .       123
 4       1     time_18        .         .
 5       2     time_3         .         .
 6       2     time_6       131         .
 7       2     time_9         .         .
 8       2     time_18      120       123
&lt;/PRE&gt;
&lt;P&gt;Which you can turn into binary 1/0 values (without the need to do an code generation) and the add up.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data for_count;
  set ds1T ;
  type_A = n(type_a);
  type_B = n(type_b);
  type_pair = type_a and type_b;
run;
proc summary data=for_count nway;
  class time ;
  var type_: ;
  output out=want(drop=_type_) sum=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;                                                type_
Obs     time      _FREQ_    type_a    type_b     pair

 1     time_18       2         1         1        1
 2     time_3        2         1         1        1
 3     time_6        2         2         0        0
 4     time_9        2         0         1        0

&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Jun 2023 20:32:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Include-a-condition-in-proc-sql-to-evaluate-if-the-variable/m-p/881805#M348439</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-06-21T20:32:41Z</dc:date>
    </item>
    <item>
      <title>Re: Include a condition in proc sql to evaluate if the variable exists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Include-a-condition-in-proc-sql-to-evaluate-if-the-variable/m-p/881814#M348441</link>
      <description>Thank you! This works perfect!</description>
      <pubDate>Wed, 21 Jun 2023 21:33:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Include-a-condition-in-proc-sql-to-evaluate-if-the-variable/m-p/881814#M348441</guid>
      <dc:creator>ANKH1</dc:creator>
      <dc:date>2023-06-21T21:33:53Z</dc:date>
    </item>
    <item>
      <title>Re: Include a condition in proc sql to evaluate if the variable exists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Include-a-condition-in-proc-sql-to-evaluate-if-the-variable/m-p/881904#M348462</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Just for having some fun*/
data ds1;
  input ID pair type $ time_3 time_6 time_9 time_18;
datalines;
1 1 a 111 134   .   .  
2 1 b 110   . 123   . 
3 2 a   . 131   . 120
4 2 b   .   .   . 123
;
proc sql;
create table temp as
select type,
       n(time_3) as time_3,
	   n(time_6) as time_6,
	   n(time_9) as time_9,
	   n(time_18) as time_18
  from ds1
   group by type;

create table temp2 as
select * from temp
union
select 'pair',
       sum(time_3=0)=0,
       sum(time_6=0)=0,
       sum(time_9=0)=0,
       sum(time_18=0)=0
  from temp;
quit;
proc transpose data=temp2 out=want;
id type;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 22 Jun 2023 13:36:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Include-a-condition-in-proc-sql-to-evaluate-if-the-variable/m-p/881904#M348462</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-06-22T13:36:44Z</dc:date>
    </item>
  </channel>
</rss>

