<?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: why is my drop not working in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/why-is-my-drop-not-working/m-p/503055#M134371</link>
    <description>&lt;P&gt;I see mainly three issues here:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) &amp;amp;num is not set anywhere in the code you provided.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;2) Your using drop statement as open code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;you have to change that to as &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76464"&gt;@s_lassen&lt;/a&gt; mentioned.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data &amp;amp;source..&amp;amp;&amp;amp;ds&amp;amp;i;
set &amp;amp;source..&amp;amp;&amp;amp;ds&amp;amp;i;
drop &amp;amp;drop;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;3) Your where clause &lt;STRONG&gt;where format in ('DATE', 'TIME')&lt;/STRONG&gt; might not include all the date &amp;amp; time formats that are in you dataset.&lt;/P&gt;
&lt;P&gt;example 1:&lt;BR /&gt;In below example I actually have date values but no format defined. In this case your where clause might not filter these columns.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
value='20oct2018'd;
run;
PROC CONTENTS NOPRINT DATA=test OUT=varout;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;example 2:&lt;BR /&gt;Here below the dataset have date values but format is different. In this case you might need to include &lt;STRONG&gt;where format in ('MMDDYY')&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
format value mmddyy10.;
value='20oct2018'd;
run;
PROC CONTENTS NOPRINT DATA=test OUT=varout;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Your where clause will not exclude all the date and time variables unless they are defined in the format you specified in where clause. So make sure you have DATE and TIME formats included in source datasets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You don't need to run PROC CONTENTS and PROC SQL to get the variables, you jsut need PROC SQL query for DICTIONARY.CLOUMNS.&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;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro dropds(num=);

%local num i;
%do i=1 %to &amp;amp;num;
data &amp;amp;source..&amp;amp;&amp;amp;ds&amp;amp;i;
set &amp;amp;source..&amp;amp;&amp;amp;ds&amp;amp;i;
run;

/* does current dataset have numeric dates and times then delete */
PROC SQL noprint;
SELECT name into :droplist
FROM dictionary.cloumns
where libname=upcase("&amp;amp;source") and upcase(memname)=upcase("&amp;amp;&amp;amp;ds&amp;amp;i") 
	and format in ('DATE9.', 'TIME5.') /* All Date &amp;amp; Time formats here */
;
QUIT;
data &amp;amp;source..&amp;amp;&amp;amp;ds&amp;amp;i;
set &amp;amp;source..&amp;amp;&amp;amp;ds&amp;amp;i;
drop SUBJECTVISITID VISITID FORMID FORMINDEX VISITINDEX &amp;amp;droplist;
run;
%end;
%mend;&lt;/CODE&gt;&lt;/PRE&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>Wed, 10 Oct 2018 12:44:20 GMT</pubDate>
    <dc:creator>SuryaKiran</dc:creator>
    <dc:date>2018-10-10T12:44:20Z</dc:date>
    <item>
      <title>why is my drop not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-is-my-drop-not-working/m-p/503030#M134358</link>
      <description>&lt;P&gt;I Have the following code:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;%macro dropds;&lt;/P&gt;&lt;P&gt;%local num i;&lt;BR /&gt;%do i=1 %to &amp;amp;num;&lt;BR /&gt;data &amp;amp;source..&amp;amp;&amp;amp;ds&amp;amp;i;&lt;BR /&gt;set &amp;amp;source..&amp;amp;&amp;amp;ds&amp;amp;i;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;PROC CONTENTS NOPRINT DATA=&amp;amp;source..&amp;amp;&amp;amp;ds&amp;amp;i OUT=varout;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;/* does current dataset have numeric dates and times then delete */&lt;BR /&gt;PROC SQL noprint;&lt;BR /&gt;SELECT name into :droplist&lt;BR /&gt;FROM varout&lt;BR /&gt;where format in ('DATE', 'TIME')&lt;BR /&gt;;&lt;BR /&gt;QUIT;&lt;/P&gt;&lt;P&gt;drop SUBJECTVISITID VISITID FORMID FORMINDEX VISITINDEX &amp;amp;droplist;&lt;BR /&gt;%end;&lt;BR /&gt;%mend;&lt;BR /&gt;&lt;BR /&gt;But in all the datasets still remain the variables (&lt;SPAN&gt;SUBJECTVISITID VISITID FORMID FORMINDEX VISITINDEX&lt;/SPAN&gt;) that should have been dropped, it seems like I am blind&lt;/P&gt;</description>
      <pubDate>Wed, 10 Oct 2018 10:59:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-is-my-drop-not-working/m-p/503030#M134358</guid>
      <dc:creator>McA</dc:creator>
      <dc:date>2018-10-10T10:59:05Z</dc:date>
    </item>
    <item>
      <title>Re: why is my drop not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-is-my-drop-not-working/m-p/503032#M134360</link>
      <description>&lt;P&gt;You never set the macro variable num, so the %do loop never iterates.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Oct 2018 11:06:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-is-my-drop-not-working/m-p/503032#M134360</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-10-10T11:06:32Z</dc:date>
    </item>
    <item>
      <title>Re: why is my drop not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-is-my-drop-not-working/m-p/503035#M134361</link>
      <description>&lt;P&gt;Apart from the problem mentioned by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;, it looks like you also have a problem with the code. You cannot insert PROC CONTENTS and PROC SQL code in the middle of a datastep, the first PROC keyword will signal the end of the datastep code, so the DROP statement is completely disconnected from the data step.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So you should find the variables to drop BEFORE running the data step. And you can just use DICTIONARY.COLUMNS, no need for a PROC CONTENTS, e.g.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  select name into :drop separated by ' '
  from dictionary.columns
  where libname="%upcase(&amp;amp;source)"
    and memname="%upcase(&amp;amp;&amp;amp;ds&amp;amp;i)"
    and (format like 'DATE%' or format like 'TIME%')
  ;
quit;

data &amp;amp;source..&amp;amp;&amp;amp;ds&amp;amp;i;
  set &amp;amp;source..&amp;amp;&amp;amp;ds&amp;amp;i;
  drop &amp;amp;drop;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Oct 2018 11:31:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-is-my-drop-not-working/m-p/503035#M134361</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2018-10-10T11:31:13Z</dc:date>
    </item>
    <item>
      <title>Re: why is my drop not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-is-my-drop-not-working/m-p/503055#M134371</link>
      <description>&lt;P&gt;I see mainly three issues here:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) &amp;amp;num is not set anywhere in the code you provided.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;2) Your using drop statement as open code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;you have to change that to as &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76464"&gt;@s_lassen&lt;/a&gt; mentioned.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data &amp;amp;source..&amp;amp;&amp;amp;ds&amp;amp;i;
set &amp;amp;source..&amp;amp;&amp;amp;ds&amp;amp;i;
drop &amp;amp;drop;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;3) Your where clause &lt;STRONG&gt;where format in ('DATE', 'TIME')&lt;/STRONG&gt; might not include all the date &amp;amp; time formats that are in you dataset.&lt;/P&gt;
&lt;P&gt;example 1:&lt;BR /&gt;In below example I actually have date values but no format defined. In this case your where clause might not filter these columns.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
value='20oct2018'd;
run;
PROC CONTENTS NOPRINT DATA=test OUT=varout;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;example 2:&lt;BR /&gt;Here below the dataset have date values but format is different. In this case you might need to include &lt;STRONG&gt;where format in ('MMDDYY')&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
format value mmddyy10.;
value='20oct2018'd;
run;
PROC CONTENTS NOPRINT DATA=test OUT=varout;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Your where clause will not exclude all the date and time variables unless they are defined in the format you specified in where clause. So make sure you have DATE and TIME formats included in source datasets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You don't need to run PROC CONTENTS and PROC SQL to get the variables, you jsut need PROC SQL query for DICTIONARY.CLOUMNS.&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;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro dropds(num=);

%local num i;
%do i=1 %to &amp;amp;num;
data &amp;amp;source..&amp;amp;&amp;amp;ds&amp;amp;i;
set &amp;amp;source..&amp;amp;&amp;amp;ds&amp;amp;i;
run;

/* does current dataset have numeric dates and times then delete */
PROC SQL noprint;
SELECT name into :droplist
FROM dictionary.cloumns
where libname=upcase("&amp;amp;source") and upcase(memname)=upcase("&amp;amp;&amp;amp;ds&amp;amp;i") 
	and format in ('DATE9.', 'TIME5.') /* All Date &amp;amp; Time formats here */
;
QUIT;
data &amp;amp;source..&amp;amp;&amp;amp;ds&amp;amp;i;
set &amp;amp;source..&amp;amp;&amp;amp;ds&amp;amp;i;
drop SUBJECTVISITID VISITID FORMID FORMINDEX VISITINDEX &amp;amp;droplist;
run;
%end;
%mend;&lt;/CODE&gt;&lt;/PRE&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>Wed, 10 Oct 2018 12:44:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-is-my-drop-not-working/m-p/503055#M134371</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-10-10T12:44:20Z</dc:date>
    </item>
    <item>
      <title>Re: why is my drop not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-is-my-drop-not-working/m-p/503100#M134386</link>
      <description>&lt;P&gt;There are more than 100 SAS supplied date, time or date time formats. Not to mention the possibility of custom formats for date, time or datetime values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Oct 2018 14:31:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-is-my-drop-not-working/m-p/503100#M134386</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-10-10T14:31:20Z</dc:date>
    </item>
    <item>
      <title>Re: why is my drop not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-is-my-drop-not-working/m-p/503673#M134637</link>
      <description>&lt;P&gt;I figured out the solution by myself. I just needed a fresh mind. I even had to change the position within the program, that no variables are dropped, which I still need.&lt;BR /&gt;&lt;BR /&gt;%MACRO renam (dsin=,dsout=);&lt;BR /&gt;PROC DATASETS LIB=MR NOLIST NOPRINT;&lt;BR /&gt;CHANGE &amp;amp;dsin = &amp;amp;dsout;&lt;BR /&gt;QUIT;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;PROC CONTENTS NOPRINT DATA=&amp;amp;dsout OUT=varout;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;PROC SQL noprint;&lt;BR /&gt;SELECT name into :droplist&lt;BR /&gt;FROM varout&lt;BR /&gt;where format in ('DATE', 'TIME');&lt;BR /&gt;QUIT;&lt;/P&gt;&lt;P&gt;DATA &amp;amp;DSOUT;&lt;BR /&gt;SET &amp;amp;DSIN;&lt;BR /&gt;DROP SUBJECTVISITID VISITID FORMID FORMINDEX VISITINDEX &amp;amp;droplist;;&lt;BR /&gt;RUN;&lt;BR /&gt;%MEND renam;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Oct 2018 10:37:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-is-my-drop-not-working/m-p/503673#M134637</guid>
      <dc:creator>McA</dc:creator>
      <dc:date>2018-10-12T10:37:31Z</dc:date>
    </item>
  </channel>
</rss>

