<?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 Filtering values prior to query in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Filtering-values-prior-to-query/m-p/638412#M19108</link>
    <description>&lt;P&gt;Hi, I want to calculate the current value divided by the minimum value in column "measurement" from visits prior to the current visit in column "type". However, first I need to use the column "jsw" to filter&lt;SPAN&gt;&amp;nbsp;for visits prior to the current visit value, and then calculate the minimum from those prior visits. This would require first searching for the minimum" jsw" value, then looking for records specific to the where "jsw" is less than the minimum "jsw" value found and then from that subset of records, pull the minimum "measurement" value for the division calculation. However, I cannot figure out to implement this in my current working code. Any solutions to this matter would be appreciated.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input Subject Type :$12. Date &amp;amp;:anydtdte. jsw procedure :$12. measurement;
	format date yymmdd10.;
	datalines;

Subject Type      Date                jsw                procedure     measurement      
500   Initial    15 AUG 2017            6                   Invasive        20        
500   Initial    15 AUG 2017            9                   Surface         35        
500   Followup   15 AUG 2018            8                   Invasive        54       
428   Followup    15 AUG 2018          56                   Outer           29        
765   Seventh     3 AUG 2018           12                   Other           13     
500   Followup    3 JUL 2018           23                   surface         98    
428   Initial     3 JUL 2017           34                   Outer           10    
765   Initial     20 JUL 2019          4                    Other           19     
610   Third       20 AUG 2019         58                    Invasive        66   
610   Initial     17 Mar 2018         25                    Invasive        17    

PROC SQL;
    create table want as
    select a.*,
        ((select measurement as lastmeasurement
         from have
         where Subject = a.Subject and procedure= a.procedure 
         having jsw = max(jsw)) -min(a.measurement))/ min(a.measurement)*100 as WantedPercent
    from have as a
    group by Subject, type
    order by Subject, type, date;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 08 Apr 2020 17:40:49 GMT</pubDate>
    <dc:creator>AshJuri</dc:creator>
    <dc:date>2020-04-08T17:40:49Z</dc:date>
    <item>
      <title>Filtering values prior to query</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Filtering-values-prior-to-query/m-p/638412#M19108</link>
      <description>&lt;P&gt;Hi, I want to calculate the current value divided by the minimum value in column "measurement" from visits prior to the current visit in column "type". However, first I need to use the column "jsw" to filter&lt;SPAN&gt;&amp;nbsp;for visits prior to the current visit value, and then calculate the minimum from those prior visits. This would require first searching for the minimum" jsw" value, then looking for records specific to the where "jsw" is less than the minimum "jsw" value found and then from that subset of records, pull the minimum "measurement" value for the division calculation. However, I cannot figure out to implement this in my current working code. Any solutions to this matter would be appreciated.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input Subject Type :$12. Date &amp;amp;:anydtdte. jsw procedure :$12. measurement;
	format date yymmdd10.;
	datalines;

Subject Type      Date                jsw                procedure     measurement      
500   Initial    15 AUG 2017            6                   Invasive        20        
500   Initial    15 AUG 2017            9                   Surface         35        
500   Followup   15 AUG 2018            8                   Invasive        54       
428   Followup    15 AUG 2018          56                   Outer           29        
765   Seventh     3 AUG 2018           12                   Other           13     
500   Followup    3 JUL 2018           23                   surface         98    
428   Initial     3 JUL 2017           34                   Outer           10    
765   Initial     20 JUL 2019          4                    Other           19     
610   Third       20 AUG 2019         58                    Invasive        66   
610   Initial     17 Mar 2018         25                    Invasive        17    

PROC SQL;
    create table want as
    select a.*,
        ((select measurement as lastmeasurement
         from have
         where Subject = a.Subject and procedure= a.procedure 
         having jsw = max(jsw)) -min(a.measurement))/ min(a.measurement)*100 as WantedPercent
    from have as a
    group by Subject, type
    order by Subject, type, date;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 08 Apr 2020 17:40:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Filtering-values-prior-to-query/m-p/638412#M19108</guid>
      <dc:creator>AshJuri</dc:creator>
      <dc:date>2020-04-08T17:40:49Z</dc:date>
    </item>
    <item>
      <title>Re: Filtering values prior to query</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Filtering-values-prior-to-query/m-p/638741#M19122</link>
      <description>&lt;P&gt;I'm having difficulties understanding exactly what you want.&lt;/P&gt;&lt;P&gt;Lets do it step by step.&lt;/P&gt;&lt;P&gt;First you need to find the current visit.&lt;/P&gt;&lt;PRE&gt;proc sql;
create table current_visit AS 
select&lt;BR /&gt;     t1.Subject, 
     max(t1.Date) format=YYMMDD10. as Date
from have t1
group by t1.Subject;
quit;&lt;/PRE&gt;&lt;P&gt;Now find the previous visits:&lt;/P&gt;&lt;PRE&gt;proc sql;
create table previous_visits as 
select
     t1.Subject, 
     t1.Type, 
     t1.Date, 
     t1.jsw, 
     t1.procedure, 
     t1.measurement
from have t1
left join current_visit t2 on (t1.Subject = t2.Subject)
where t1.Date &amp;lt; t2.Date;
quit;&lt;/PRE&gt;&lt;P&gt;And now I'm lost where to go. Not even sure if the path was right.&lt;/P&gt;&lt;P&gt;But manly do it step by step.&lt;/P&gt;&lt;P&gt;One table for each value.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Apr 2020 16:59:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Filtering-values-prior-to-query/m-p/638741#M19122</guid>
      <dc:creator>RicHen</dc:creator>
      <dc:date>2020-04-09T16:59:27Z</dc:date>
    </item>
  </channel>
</rss>

