<?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 requested regarding logic of SAS code in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Help-requested-regarding-logic-of-SAS-code/m-p/80365#M17298</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;There's more than I can tackle right now, but I'll get you started.&amp;nbsp; One DATA step begins:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set test;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That step creates TEST1 by copying what's in TEST and making a few changes.&amp;nbsp; More specifically, it expects that VAR1 will be blank some of the time.&amp;nbsp; In that case, it should copy the most recent nonblank VAR1.&amp;nbsp; It would be faster to combine the first three steps:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test3;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; set test;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; if var2=' ' then delete;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; if var1 ne ' ' then temp=var1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; else var1=temp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; retain temp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; if upcase(compress(var1)) in ('UPDATEDATE', 'GENERICNAME', ... etc.);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;An IF statement (without a THEN result) determines which observations should remain and deletes the rest.&amp;nbsp; And RETAIN holds on to the current value of a variable, even when moving from one observation to the next.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In general, you might need to play with these tools to get the hang of them.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 18 Mar 2013 21:43:08 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2013-03-18T21:43:08Z</dc:date>
    <item>
      <title>Help requested regarding logic of SAS code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-requested-regarding-logic-of-SAS-code/m-p/80364#M17297</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;I am&amp;nbsp; working on modifying an existing SAS code to extract data from a text file and have output in an excel file. The code is working fine with the old input text file but however I am losing quite many observations when I give the new input text file.I have prior programming experience in Java-J2EE and PL-SQL and leveraging on my previous experience, I have modified the code slightly but as I am totally new with SAS, I am having problem comprehending the logic of the program. I would be really grateful if someone in this community could explain in few lines&amp;nbsp; the logic of the code to me and likewise I can modify the program. I paste the code below for reference.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance for your kind help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Archita&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;libname Mylib "C:\Users\PhD\SAS\Workspace\Step1";&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data WORK.test;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let _EFIERR_ = 0; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; infile 'C:\Users\PhD\SAS\Workspace\a.txt' delimiter='09'x MISSOVER DSD lrecl=32767 firstobs=1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; informat VAR1 $15. ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; informat VAR2 $200. ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; informat VAR3 $14. ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; informat VAR4 $13. ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; informat VAR5 $16. ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; informat VAR6 $22. ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; format VAR1 $15. ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; format VAR2 $200. ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; format VAR3 $14. ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; format VAR4 $13. ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; format VAR5 $16. ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; format VAR6 $22. ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; input&lt;/P&gt;&lt;P&gt;&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; Var1 $&lt;/P&gt;&lt;P&gt;&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; Var2 $&lt;/P&gt;&lt;P&gt;&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; VAR3 $&lt;/P&gt;&lt;P&gt;&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; VAR4 $&lt;/P&gt;&lt;P&gt;&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; VAR5 $&lt;/P&gt;&lt;P&gt;&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; VAR6 $&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if _ERROR_ then call symput('_EFIERR_',1);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; keep var1 var2;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc import datafile="C:\Users\PhD\SAS\Workspace\country_list.xls"&lt;/P&gt;&lt;P&gt;out = Mylib.country_list dbms = xls replace;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;options mprint merror symbolgen;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro ETL_Phase1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set test;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if var1 ~= '' then &lt;/P&gt;&lt;P&gt;&amp;nbsp; do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; temp = var1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; else &lt;/P&gt;&lt;P&gt;&amp;nbsp; do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; var1 = temp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; retain temp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; drop temp;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test2;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set test1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if var2 = '' then delete;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test3;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set test2;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if (upcase(compress(var1)) = "UPDATEDATE" or &lt;/P&gt;&lt;P&gt;&amp;nbsp; upcase(compress(var1)) = "GENERICNAME" or /*modified 15Mar2013*/ &lt;/P&gt;&lt;P&gt;&amp;nbsp; upcase(compress(var1)) = "LATESTPHASE" or &lt;/P&gt;&lt;P&gt;&amp;nbsp; upcase(compress(var1)) = "ACTIVEPROGRAM" or &lt;/P&gt;&lt;P&gt;&amp;nbsp; upcase(compress(var1)) = "COMPANY" or &lt;/P&gt;&lt;P&gt;&amp;nbsp; upcase(compress(var1)) = "CLASSDESCRIPTION" or /*modified 14Mar2013*/ &lt;/P&gt;&lt;P&gt;&amp;nbsp; upcase(compress(var1)) = "INDICATION" or &lt;/P&gt;&lt;P&gt;&amp;nbsp; upcase(compress(var1)) = "PATENTDATA" or &lt;/P&gt;&lt;P&gt;&amp;nbsp; /*upcase(compress(var1)) = "ATCPROFILES" or */&lt;/P&gt;&lt;P&gt;&amp;nbsp; upcase(compress(var1)) = "ACTION" or &lt;/P&gt;&lt;P&gt;&amp;nbsp; upcase(compress(var1)) = "HISTORY"); &lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test4;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set test3;&lt;/P&gt;&lt;P&gt;&amp;nbsp; retain count 0;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if upcase(compress(var1)) = "UPDATEDATE" then count = count + 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; retain count;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; create table template1 as&lt;/P&gt;&lt;P&gt;&amp;nbsp; select unique var1 from test4;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; create table template2 as&lt;/P&gt;&lt;P&gt;&amp;nbsp; select unique count from test4;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; create table template as&lt;/P&gt;&lt;P&gt;&amp;nbsp; select * from template1, template2;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort data = template;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by var1 count;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort data = test4;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by var1 count;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data finaldata;&lt;/P&gt;&lt;P&gt;&amp;nbsp; merge template test4;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by var1 count;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if strip(upcase(var1)) = "HISTORY" then temp = 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; else temp = 0;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort data = finaldata;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by count temp;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc transpose data = Finaldata out = a_out1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; var var1 var2;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by count;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* Capture the number of variables in the dataset into a macro variable - nvars */&lt;/P&gt;&lt;P&gt;%let dsid = %sysfunc(open(work.a_out1, i));&lt;/P&gt;&lt;P&gt;%let nvars = %sysfunc(attrn(&amp;amp;dsid, nvars));&lt;/P&gt;&lt;P&gt;%if &amp;amp;dsid &amp;gt; 0 %then&lt;/P&gt;&lt;P&gt;&amp;nbsp; %let rc=%sysfunc(close(&amp;amp;dsid));&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data Mylib.a_out1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array cols (%eval(&amp;amp;nvars-2)) $200. col1-col%eval(&amp;amp;nvars-2);&lt;/P&gt;&lt;P&gt;&amp;nbsp; array histories (%eval(&amp;amp;nvars-2)) $200. history1-history%eval(&amp;amp;nvars-2);&lt;/P&gt;&lt;P&gt;&amp;nbsp; set a_out1(where=(strip(upcase(_name_))="VAR2"));&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; /*atc_Profiles = col1;*/&lt;/P&gt;&lt;P&gt;&amp;nbsp; action = col1;/*modified 14 March 2013*/&lt;/P&gt;&lt;P&gt;&amp;nbsp; active_program = col2;/*modified 14 March 2013*/&lt;/P&gt;&lt;P&gt;&amp;nbsp; company= col3;/*modified 14 March 2013*/&lt;/P&gt;&lt;P&gt;&amp;nbsp; product_name = col4;/*modified 14 March 2013*/&lt;/P&gt;&lt;P&gt;&amp;nbsp; indication = col5;/*modified 14 March 2013*/&lt;/P&gt;&lt;P&gt;&amp;nbsp; latest_phase = col6;/*modified 14 March 2013*/&lt;/P&gt;&lt;P&gt;&amp;nbsp; patent_data = col7;/*modified 14 March 2013*/&lt;/P&gt;&lt;P&gt;&amp;nbsp; update_date= col8;/*modified 14 March 2013*/&lt;/P&gt;&lt;P&gt;&amp;nbsp; classdescription=col9;/*modified 14 March 2013*/&lt;/P&gt;&lt;P&gt;&amp;nbsp; do i = 1 to %eval(&amp;amp;nvars-2);&lt;/P&gt;&lt;P&gt;&amp;nbsp; if i&amp;gt;=11 then&lt;/P&gt;&lt;P&gt;&amp;nbsp; histories(i-10) = cols(i);&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; drop col1-col%eval(&amp;amp;nvars-2) _name_ i;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* Obtain the country list into a macro variable delimited by ":" */&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;/P&gt;&lt;P&gt;&amp;nbsp; select country into : country_list separated by ':' from Mylib.Country_list;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* Extract data */&lt;/P&gt;&lt;P&gt;data Mylib.A;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set Mylib.a_out1(obs=350);&lt;/P&gt;&lt;P&gt;&amp;nbsp; retain agree_check agree_term_check agree_no_check;&lt;/P&gt;&lt;P&gt;&amp;nbsp; retain precli_check; /* C002 */&lt;/P&gt;&lt;P&gt;&amp;nbsp; retain phase1_check phase1a_check phase1b_check phase2_check phase3_check phase1_2_check phase2_3_check phase1_3_check;&lt;/P&gt;&lt;P&gt;&amp;nbsp; retain marketed_check registered_check marketed_usa_check registered_usa_check;&lt;/P&gt;&lt;P&gt;&amp;nbsp; retain not_reco_check not_reco_usa_check orphan_drug_check fasttrack_check;&lt;/P&gt;&lt;P&gt;&amp;nbsp; retain country_list "&amp;amp;country_list";&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; format agree_1-agree_10 date9.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; format agree_term_1-agree_term_10 date9.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; format phase1_1-phase1_5 date9.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; format phase2_1-phase2_5 date9.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; format phase3_1-phase3_5 date9.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; format phase1a_1-phase1a_5 date9.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; format phase1b_1-phase1b_5 date9.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; format phase1_2_1-phase1_2_5 date9.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; format phase2_3_1-phase2_3_5 date9.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; format phase1_3_1-phase1_3_5 date9.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; format marketed date9.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; format registered date9.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; format marketed_usa date9.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; format registered_usa date9.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; format orphan_drug date9.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; format fasttrack date9.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; format not_reco_1-not_reco_5 date9.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; format not_reco_usa date9.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; format country1-country50 $30.;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array histories (%eval(&amp;amp;nvars-2)) $200. history1-history%eval(&amp;amp;nvars-2);/*modified nvars-12 14 March 2013*/&lt;/P&gt;&lt;P&gt;&amp;nbsp; array countries (%eval(&amp;amp;nvars-2)) $200. country1-country%eval(&amp;amp;nvars-2);/*modified nvars-12 14 March 2013*/&lt;/P&gt;&lt;P&gt;&amp;nbsp; array agree_ (10) agree_1-agree_10;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array agree_names (10) $200. agree_name1-agree_name10;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array agree_termins (10) $200. agree_termin1-agree_termin10;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array agree_term_ (10) agree_term_1-agree_term_10;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array phase1_ (5) phase1_1-phase1_5;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array phase1a_ (5) phase1a_1-phase1a_5;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array phase1b_ (5) phase1b_1-phase1b_5;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array phase2_ (5) phase2_1-phase2_5;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array phase3_ (5) phase3_1-phase3_5;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array phase1_2_ (5) phase1_2_1-phase1_2_5;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array phase2_3_ (5) phase2_3_1-phase2_3_5;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array phase1_3_ (5) phase1_3_1-phase1_3_5;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array not_reco (5) not_reco_1-not_reco_5;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array country (50) $30. country1-country50;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if _n_ = 1 then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; agree_check = prxparse("/(agreement)|(collaboration)|(collaborative)|(co\-promotion)|(option)|(licensed to)/i");&lt;/P&gt;&lt;P&gt;&amp;nbsp; agree_term_check = prxparse("/(No longer in development with originator)|(terminated)/i");&lt;/P&gt;&lt;P&gt;&amp;nbsp; /* C001 */&lt;/P&gt;&lt;P&gt;&amp;nbsp; agree_no_check = prxparse("/(extended)|(amended)|(revision of)/i");&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; phase1_check = prxparse("/phase I[^abI\/]/i");&lt;/P&gt;&lt;P&gt;&amp;nbsp; phase1a_check = prxparse("/phase Ia/i");&lt;/P&gt;&lt;P&gt;&amp;nbsp; phase1b_check = prxparse("/phase Ib/i");&lt;/P&gt;&lt;P&gt;&amp;nbsp; phase2_check = prxparse("/phase II[^\/I]/i");&lt;/P&gt;&lt;P&gt;&amp;nbsp; phase3_check = prxparse("/phase III[^\/]/i");&lt;/P&gt;&lt;P&gt;&amp;nbsp; phase1_2_check = prxparse("/phase I\/II/i");&lt;/P&gt;&lt;P&gt;&amp;nbsp; phase2_3_check = prxparse("/phase II\/III/i");&lt;/P&gt;&lt;P&gt;&amp;nbsp; phase1_3_check = prxparse("/phase I\/III/i");&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; marketed_check = prxparse("/marketed/i");&lt;/P&gt;&lt;P&gt;&amp;nbsp; registered_check = prxparse("/registered/i");&lt;/P&gt;&lt;P&gt;&amp;nbsp; marketed_usa_check = prxparse("/marketed\,\s?usa/i");&lt;/P&gt;&lt;P&gt;&amp;nbsp; registered_usa_check = prxparse("/registered\,\s?usa/i");&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; not_reco_check = prxparse("/not recommended/i");&lt;/P&gt;&lt;P&gt;&amp;nbsp; not_reco_usa_check = prxparse("/not recommended\,\s?usa/i");&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; orphan_drug_check = prxparse("/orphan\s?drug/i");&lt;/P&gt;&lt;P&gt;&amp;nbsp; fasttrack_check = prxparse("/fast\s?track/i");&lt;/P&gt;&lt;P&gt;&amp;nbsp; precli_check = prxparse("/preclinical/i");&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; agree_cnt = 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; agree_term_cnt = 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; phase1_cnt = 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; phase1a_cnt = 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; phase1b_cnt = 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; phase2_cnt = 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; phase3_cnt = 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; phase1_2_cnt = 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; phase2_3_cnt = 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; phase1_3_cnt = 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; not_reco_cnt = 1;&lt;/P&gt;&lt;P&gt;/* marketed_cnt=1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; registered_cnt=1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; marketed_usa_cnt=1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; registered_usa_cnt=1;*/&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do i = 1 to dim(histories);&lt;/P&gt;&lt;P&gt;&amp;nbsp; /* Agreement */&lt;/P&gt;&lt;P&gt;&amp;nbsp; if (prxmatch(agree_check, histories(i)) and not&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; prxmatch(agree_term_check, histories(i)) and not &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; prxmatch(agree_no_check, histories(i)))&lt;/P&gt;&lt;P&gt;&amp;nbsp; then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if agree_cnt &amp;lt;= 10 then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; len = length(compress(scan(histories(i), 1, ':')));&lt;/P&gt;&lt;P&gt;&amp;nbsp; if len = 7 then&lt;/P&gt;&lt;P&gt;&amp;nbsp; agree_(agree_cnt) = input(('01' || compress(scan(histories(i), 1, ':'))), date9.);&lt;/P&gt;&lt;P&gt;&amp;nbsp; else if len = 4 then &lt;/P&gt;&lt;P&gt;&amp;nbsp; agree_(agree_cnt) = input(('1306' || compress(scan(histories(i), 1, ':'))), ddmmyy8.);&lt;/P&gt;&lt;P&gt;&amp;nbsp; agree_names(agree_cnt) = histories(i);&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; agree_cnt = agree_cnt + 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; /* Agreement Terminated */&lt;/P&gt;&lt;P&gt;&amp;nbsp; if prxmatch(agree_term_check, histories(i)) then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if agree_term_cnt &amp;lt;= 10 then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; len = length(compress(scan(histories(i), 1, ':')));&lt;/P&gt;&lt;P&gt;&amp;nbsp; if len = 7 then&lt;/P&gt;&lt;P&gt;&amp;nbsp; agree_term_(agree_term_cnt) = input(('01' || compress(scan(histories(i), 1, ':'))), date9.);&lt;/P&gt;&lt;P&gt;&amp;nbsp; else if len = 4 then &lt;/P&gt;&lt;P&gt;&amp;nbsp; agree_term_(agree_term_cnt) = input(('1306' || compress(scan(histories(i), 1, ':'))), ddmmyy8.);&lt;/P&gt;&lt;P&gt;&amp;nbsp; agree_termins(agree_term_cnt) = histories(i);&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; agree_term_cnt = agree_term_cnt + 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; /* Phase I */&lt;/P&gt;&lt;P&gt;&amp;nbsp; if prxmatch(phase1_check, histories(i)) and not prxmatch(phase2_check, histories(i)) then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if phase1_cnt &amp;lt;= 5 then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; len = length(compress(scan(histories(i), 1, ':')));&lt;/P&gt;&lt;P&gt;&amp;nbsp; if len = 7 then&lt;/P&gt;&lt;P&gt;&amp;nbsp; phase1_(phase1_cnt) = input(('01' || compress(scan(histories(i), 1, ':'))), date9.);&lt;/P&gt;&lt;P&gt;&amp;nbsp; else if len = 4 then &lt;/P&gt;&lt;P&gt;&amp;nbsp; phase1_(phase1_cnt) = input(('1306' || compress(scan(histories(i), 1, ':'))), ddmmyy8.);&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; phase1_cnt = phase1_cnt + 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; /* Phase Ia */&lt;/P&gt;&lt;P&gt;&amp;nbsp; if prxmatch(phase1a_check, histories(i)) then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if phase1a_cnt &amp;lt;= 5 then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; len = length(compress(scan(histories(i), 1, ':')));&lt;/P&gt;&lt;P&gt;&amp;nbsp; if len = 7 then&lt;/P&gt;&lt;P&gt;&amp;nbsp; phase1a_(phase1a_cnt) = input(('01' || compress(scan(histories(i), 1, ':'))), date9.);&lt;/P&gt;&lt;P&gt;&amp;nbsp; else if len = 4 then &lt;/P&gt;&lt;P&gt;&amp;nbsp; phase1a_(phase1a_cnt) = input(('1306' || compress(scan(histories(i), 1, ':'))), ddmmyy8.);&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; phase1a_cnt = phase1a_cnt + 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; /* Phase Ib */&lt;/P&gt;&lt;P&gt;&amp;nbsp; if prxmatch(phase1b_check, histories(i)) then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if phase1b_cnt &amp;lt;= 5 then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; len = length(compress(scan(histories(i), 1, ':')));&lt;/P&gt;&lt;P&gt;&amp;nbsp; if len = 7 then&lt;/P&gt;&lt;P&gt;&amp;nbsp; phase1b_(phase1b_cnt) = input(('01' || compress(scan(histories(i), 1, ':'))), date9.);&lt;/P&gt;&lt;P&gt;&amp;nbsp; else if len = 4 then &lt;/P&gt;&lt;P&gt;&amp;nbsp; phase1b_(phase1b_cnt) = input(('1306' || compress(scan(histories(i), 1, ':'))), ddmmyy8.);&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; phase1b_cnt = phase1b_cnt + 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; /* Phase II */&lt;/P&gt;&lt;P&gt;&amp;nbsp; if prxmatch(phase2_check, histories(i)) and not prxmatch(phase3_check, histories(i)) then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if phase2_cnt &amp;lt;= 5 then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; len = length(compress(scan(histories(i), 1, ':')));&lt;/P&gt;&lt;P&gt;&amp;nbsp; if len = 7 then&lt;/P&gt;&lt;P&gt;&amp;nbsp; phase2_(phase2_cnt) = input(('01' || compress(scan(histories(i), 1, ':'))), date9.);&lt;/P&gt;&lt;P&gt;&amp;nbsp; else if len = 4 then &lt;/P&gt;&lt;P&gt;&amp;nbsp; phase2_(phase2_cnt) = input(('1306' || compress(scan(histories(i), 1, ':'))), ddmmyy8.);&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; phase2_cnt = phase2_cnt + 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; /* Phase III */&lt;/P&gt;&lt;P&gt;&amp;nbsp; if prxmatch(phase3_check, histories(i)) then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if phase3_cnt &amp;lt;= 5 then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; len = length(compress(scan(histories(i), 1, ':')));&lt;/P&gt;&lt;P&gt;&amp;nbsp; if len = 7 then&lt;/P&gt;&lt;P&gt;&amp;nbsp; phase3_(phase3_cnt) = input(('01' || compress(scan(histories(i), 1, ':'))), date9.);&lt;/P&gt;&lt;P&gt;&amp;nbsp; else if len = 4 then &lt;/P&gt;&lt;P&gt;&amp;nbsp; phase3_(phase3_cnt) = input(('1306' || compress(scan(histories(i), 1, ':'))), ddmmyy8.);&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; phase3_cnt = phase3_cnt + 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp; /* Phase I/II */&lt;/P&gt;&lt;P&gt;&amp;nbsp; if prxmatch(phase1_2_check, histories(i)) then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if phase1_2_cnt &amp;lt;= 5 then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; len = length(compress(scan(histories(i), 1, ':')));&lt;/P&gt;&lt;P&gt;&amp;nbsp; if len = 7 then&lt;/P&gt;&lt;P&gt;&amp;nbsp; phase1_2_(phase1_2_cnt) = input(('01' || compress(scan(histories(i), 1, ':'))), date9.);&lt;/P&gt;&lt;P&gt;&amp;nbsp; else if len = 4 then &lt;/P&gt;&lt;P&gt;&amp;nbsp; phase1_2_(phase1_2_cnt) = input(('1306' || compress(scan(histories(i), 1, ':'))), ddmmyy8.);&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; phase1_2_cnt = phase1_2_cnt + 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp; /* Phase II/III */&lt;/P&gt;&lt;P&gt;&amp;nbsp; if prxmatch(phase2_3_check, histories(i)) then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if phase2_3_cnt &amp;lt;= 5 then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; len = length(compress(scan(histories(i), 1, ':')));&lt;/P&gt;&lt;P&gt;&amp;nbsp; if len = 7 then&lt;/P&gt;&lt;P&gt;&amp;nbsp; phase2_3_(phase2_3_cnt) = input(('01' || compress(scan(histories(i), 1, ':'))), date9.);&lt;/P&gt;&lt;P&gt;&amp;nbsp; else if len = 4 then &lt;/P&gt;&lt;P&gt;&amp;nbsp; phase2_3_(phase2_3_cnt) = input(('1306' || compress(scan(histories(i), 1, ':'))), ddmmyy8.);&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; phase2_3_cnt = phase2_3_cnt + 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp; /* Phase I/III */&lt;/P&gt;&lt;P&gt;&amp;nbsp; if prxmatch(phase1_3_check, histories(i)) then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if phase1_3_cnt &amp;lt;= 5 then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; len = length(compress(scan(histories(i), 1, ':')));&lt;/P&gt;&lt;P&gt;&amp;nbsp; if len = 7 then&lt;/P&gt;&lt;P&gt;&amp;nbsp; phase1_3_(phase1_3_cnt) = input(('01' || compress(scan(histories(i), 1, ':'))), date9.);&lt;/P&gt;&lt;P&gt;&amp;nbsp; else if len = 4 then &lt;/P&gt;&lt;P&gt;&amp;nbsp; phase1_3_(phase1_3_cnt) = input(('1306' || compress(scan(histories(i), 1, ':'))), ddmmyy8.);&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; phase1_3_cnt = phase1_3_cnt + 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; /* Marketed */&lt;/P&gt;&lt;P&gt;&amp;nbsp; if prxmatch(marketed_check, histories(i)) and not prxmatch(marketed_usa_check, histories(i)) then do;&lt;/P&gt;&lt;P&gt;/* if marketed_cnt &amp;lt;= 1 then do;*/&lt;/P&gt;&lt;P&gt;&amp;nbsp; len = length(compress(scan(histories(i), 1, ':')));&lt;/P&gt;&lt;P&gt;&amp;nbsp; if len = 7 then&lt;/P&gt;&lt;P&gt;&amp;nbsp; marketed = input(('01' || compress(scan(histories(i), 1, ':'))), date9.);&lt;/P&gt;&lt;P&gt;&amp;nbsp; else if len = 4 then &lt;/P&gt;&lt;P&gt;&amp;nbsp; marketed = input(('1306' || compress(scan(histories(i), 1, ':'))), ddmmyy8.);&lt;/P&gt;&lt;P&gt;/* end; */&lt;/P&gt;&lt;P&gt;/* marketed_cnt = marketed_cnt + 1; */&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; /* Marketed USA */&lt;/P&gt;&lt;P&gt;&amp;nbsp; if prxmatch(marketed_usa_check, histories(i)) then do;&lt;/P&gt;&lt;P&gt;/* if marketed_usa_cnt &amp;lt;= 1 then do;*/&lt;/P&gt;&lt;P&gt;&amp;nbsp; len = length(compress(scan(histories(i), 1, ':')));&lt;/P&gt;&lt;P&gt;&amp;nbsp; if len = 7 then&lt;/P&gt;&lt;P&gt;&amp;nbsp; marketed_usa = input(('01' || compress(scan(histories(i), 1, ':'))), date9.);&lt;/P&gt;&lt;P&gt;&amp;nbsp; else if len = 4 then &lt;/P&gt;&lt;P&gt;&amp;nbsp; marketed_usa = input(('1306' || compress(scan(histories(i), 1, ':'))), ddmmyy8.);&lt;/P&gt;&lt;P&gt;/* end; */&lt;/P&gt;&lt;P&gt;/* marketed_usa_cnt = marketed_usa_cnt + 1;*/&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; /* registered */&lt;/P&gt;&lt;P&gt;&amp;nbsp; if prxmatch(registered_check, histories(i)) and not prxmatch(registered_usa_check, histories(i)) then do;&lt;/P&gt;&lt;P&gt;/* if registered_cnt &amp;lt;= 1 then do; */&lt;/P&gt;&lt;P&gt;&amp;nbsp; len = length(compress(scan(histories(i), 1, ':')));&lt;/P&gt;&lt;P&gt;&amp;nbsp; if len = 7 then&lt;/P&gt;&lt;P&gt;&amp;nbsp; registered = input(('01' || compress(scan(histories(i), 1, ':'))), date9.);&lt;/P&gt;&lt;P&gt;&amp;nbsp; else if len = 4 then &lt;/P&gt;&lt;P&gt;&amp;nbsp; registered = input(('1306' || compress(scan(histories(i), 1, ':'))), ddmmyy8.);&lt;/P&gt;&lt;P&gt;/* end; */&lt;/P&gt;&lt;P&gt;/* registered_cnt = registered_cnt + 1;*/&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; /* registered USA */&lt;/P&gt;&lt;P&gt;&amp;nbsp; if prxmatch(registered_usa_check, histories(i)) then do;&lt;/P&gt;&lt;P&gt;/* if registered_usa_cnt &amp;lt;= 1 then do; */&lt;/P&gt;&lt;P&gt;&amp;nbsp; len = length(compress(scan(histories(i), 1, ':')));&lt;/P&gt;&lt;P&gt;&amp;nbsp; if len = 7 then&lt;/P&gt;&lt;P&gt;&amp;nbsp; registered_usa = input(('01' || compress(scan(histories(i), 1, ':'))), date9.);&lt;/P&gt;&lt;P&gt;&amp;nbsp; else if len = 4 then &lt;/P&gt;&lt;P&gt;&amp;nbsp; registered_usa = input(('1306' || compress(scan(histories(i), 1, ':'))), ddmmyy8.);&lt;/P&gt;&lt;P&gt;/* end;*/&lt;/P&gt;&lt;P&gt;/* registered_usa_cnt = registered_usa_cnt + 1;*/&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; /* Not Recommended */&lt;/P&gt;&lt;P&gt;&amp;nbsp; if prxmatch(not_reco_check, histories(i)) and not prxmatch(not_reco_usa_check, histories(i)) then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if not_reco_cnt &amp;lt;= 5 then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; len = length(compress(scan(histories(i), 1, ':')));&lt;/P&gt;&lt;P&gt;&amp;nbsp; if len = 7 then&lt;/P&gt;&lt;P&gt;&amp;nbsp; not_reco(not_reco_cnt) = input(('01' || compress(scan(histories(i), 1, ':'))), date9.);&lt;/P&gt;&lt;P&gt;&amp;nbsp; else if len = 4 then &lt;/P&gt;&lt;P&gt;&amp;nbsp; not_reco(not_reco_cnt) = input(('1306' || compress(scan(histories(i), 1, ':'))), ddmmyy8.);&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; not_reco_cnt = not_reco_cnt + 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; /* Not Recommended USA */&lt;/P&gt;&lt;P&gt;&amp;nbsp; if prxmatch(not_reco_usa_check, histories(i)) then do;&lt;/P&gt;&lt;P&gt;/* if not_reco_cnt &amp;lt;= 1 then do; */&lt;/P&gt;&lt;P&gt;&amp;nbsp; len = length(compress(scan(histories(i), 1, ':')));&lt;/P&gt;&lt;P&gt;&amp;nbsp; if len = 7 then&lt;/P&gt;&lt;P&gt;&amp;nbsp; not_reco_usa = input(('01' || compress(scan(histories(i), 1, ':'))), date9.);&lt;/P&gt;&lt;P&gt;&amp;nbsp; else if len = 4 then &lt;/P&gt;&lt;P&gt;&amp;nbsp; not_reco_usa = input(('1306' || compress(scan(histories(i), 1, ':'))), ddmmyy8.);&lt;/P&gt;&lt;P&gt;/* end;*/&lt;/P&gt;&lt;P&gt;/* not_reco_cnt = not_reco_cnt + 1; */&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; /* Orphan Drug */&lt;/P&gt;&lt;P&gt;&amp;nbsp; if prxmatch(orphan_drug_check, histories(i)) then do;&lt;/P&gt;&lt;P&gt;/* if not_reco_cnt &amp;lt;= 1 then do; */&lt;/P&gt;&lt;P&gt;&amp;nbsp; len = length(compress(scan(histories(i), 1, ':')));&lt;/P&gt;&lt;P&gt;&amp;nbsp; if len = 7 then&lt;/P&gt;&lt;P&gt;&amp;nbsp; orphan_drug = input(('01' || compress(scan(histories(i), 1, ':'))), date9.);&lt;/P&gt;&lt;P&gt;&amp;nbsp; else if len = 4 then &lt;/P&gt;&lt;P&gt;&amp;nbsp; orphan_drug = input(('1306' || compress(scan(histories(i), 1, ':'))), ddmmyy8.);&lt;/P&gt;&lt;P&gt;/* end;*/&lt;/P&gt;&lt;P&gt;/* not_reco_cnt = not_reco_cnt + 1; */&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; /* Fast Track */&lt;/P&gt;&lt;P&gt;&amp;nbsp; if prxmatch(fasttrack_check, histories(i)) then do;&lt;/P&gt;&lt;P&gt;/* if not_reco_cnt &amp;lt;= 1 then do; */&lt;/P&gt;&lt;P&gt;&amp;nbsp; len = length(compress(scan(histories(i), 1, ':')));&lt;/P&gt;&lt;P&gt;&amp;nbsp; if len = 7 then&lt;/P&gt;&lt;P&gt;&amp;nbsp; fasttrack = input(('01' || compress(scan(histories(i), 1, ':'))), date9.);&lt;/P&gt;&lt;P&gt;&amp;nbsp; else if len = 4 then &lt;/P&gt;&lt;P&gt;&amp;nbsp; fasttrack = input(('1306' || compress(scan(histories(i), 1, ':'))), ddmmyy8.);&lt;/P&gt;&lt;P&gt;/* end; */&lt;/P&gt;&lt;P&gt;/* not_reco_cnt = not_reco_cnt + 1; */&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* To identify unique countries in a given project */&lt;/P&gt;&lt;P&gt;&amp;nbsp; /* Country search would happen only if the history part of the information&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; contains: preclinical, phase I, phase II and phase III phases (C003) */&lt;/P&gt;&lt;P&gt;&amp;nbsp; if (prxmatch(precli_check, histories(i)) or &lt;/P&gt;&lt;P&gt;&amp;nbsp; prxmatch(phase1_check, histories(i)) or&lt;/P&gt;&lt;P&gt;&amp;nbsp; prxmatch(phase1a_check, histories(i)) or&lt;/P&gt;&lt;P&gt;&amp;nbsp; prxmatch(phase1b_check, histories(i)) or&lt;/P&gt;&lt;P&gt;&amp;nbsp; prxmatch(phase2_check, histories(i)) or&lt;/P&gt;&lt;P&gt;&amp;nbsp; prxmatch(phase3_check, histories(i)) or&lt;/P&gt;&lt;P&gt;&amp;nbsp; prxmatch(phase1_2_check, histories(i)) or&lt;/P&gt;&lt;P&gt;&amp;nbsp; prxmatch(phase2_3_check, histories(i)) or&lt;/P&gt;&lt;P&gt;&amp;nbsp; prxmatch(phase1_3_check, histories(i))) then do;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; j = 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do while(scan(country_list, j, ":") ~= ""); /* loop for every country in the list */&lt;/P&gt;&lt;P&gt;&amp;nbsp; curr_country = scan(country_list, j, ":");&lt;/P&gt;&lt;P&gt;&amp;nbsp; /* Step to avoid any other substring matches with abbreviations like USA, UK or EU */&lt;/P&gt;&lt;P&gt;&amp;nbsp; if strip(upcase(curr_country)) not in ("USA", "UK", "EU") then &lt;/P&gt;&lt;P&gt;&amp;nbsp; curr_history = upcase(strip(histories(i)));&lt;/P&gt;&lt;P&gt;&amp;nbsp; else&lt;/P&gt;&lt;P&gt;&amp;nbsp; curr_history = strip(histories(i));&lt;/P&gt;&lt;P&gt;&amp;nbsp; /* A country is found in the history */&lt;/P&gt;&lt;P&gt;&amp;nbsp; if index(strip(curr_history), upcase(strip(curr_country))) ~= 0 then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; k = 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; found = 0;&lt;/P&gt;&lt;P&gt;&amp;nbsp; /* Check the list of already found countries to see if this country has &lt;/P&gt;&lt;P&gt;&amp;nbsp; already occured. If so, then ignore, otherwise increase the count of &lt;/P&gt;&lt;P&gt;&amp;nbsp; countries found. Also add the current country to the list of found &lt;/P&gt;&lt;P&gt;&amp;nbsp; countries. */&lt;/P&gt;&lt;P&gt;&amp;nbsp; do while(country(k) ~= "" and found ~= 1);&lt;/P&gt;&lt;P&gt;&amp;nbsp; if upcase(strip(country(k))) = upcase(strip(curr_country)) then &lt;/P&gt;&lt;P&gt;&amp;nbsp; found = 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; k = k + 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if found = 0 then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; country(k) = upcase(strip(curr_country));&lt;/P&gt;&lt;P&gt;&amp;nbsp; total_countries = k;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; j = j + 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end; /* loop for every country in the list ends */&lt;/P&gt;&lt;P&gt;&amp;nbsp; end; &lt;/P&gt;&lt;P&gt;&amp;nbsp; end; /* Filter on Phases for Country Search (C003 ends) */&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; drop i len; &lt;/P&gt;&lt;P&gt;&amp;nbsp; drop agree_check agree_term_check agree_no_check;&lt;/P&gt;&lt;P&gt;&amp;nbsp; drop precli_check; /* C002 ends */&lt;/P&gt;&lt;P&gt;&amp;nbsp; drop phase1_check phase1a_check phase1b_check phase2_check phase3_check phase1_2_check phase2_3_check phase1_3_check;&lt;/P&gt;&lt;P&gt;&amp;nbsp; drop marketed_check registered_check marketed_usa_check registered_usa_check;&lt;/P&gt;&lt;P&gt;&amp;nbsp; drop not_reco_check not_reco_usa_check orphan_drug_check fasttrack_check;&lt;/P&gt;&lt;P&gt;&amp;nbsp; drop agree_cnt agree_term_cnt phase1_cnt phase1a_cnt phase1b_cnt phase2_cnt phase3_cnt phase1_2_cnt phase2_3_cnt phase1_3_cnt not_reco_cnt; &lt;/P&gt;&lt;P&gt;&amp;nbsp; drop history1-history%eval(&amp;amp;nvars-10); /*modified nvars-12 15 March 2013*/&lt;/P&gt;&lt;P&gt;&amp;nbsp; drop j k curr_country country_list curr_history found; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%mend ETL_Phase1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%ETL_Phase1;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 Mar 2013 21:25:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-requested-regarding-logic-of-SAS-code/m-p/80364#M17297</guid>
      <dc:creator>arch</dc:creator>
      <dc:date>2013-03-18T21:25:34Z</dc:date>
    </item>
    <item>
      <title>Re: Help requested regarding logic of SAS code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-requested-regarding-logic-of-SAS-code/m-p/80365#M17298</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;There's more than I can tackle right now, but I'll get you started.&amp;nbsp; One DATA step begins:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set test;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That step creates TEST1 by copying what's in TEST and making a few changes.&amp;nbsp; More specifically, it expects that VAR1 will be blank some of the time.&amp;nbsp; In that case, it should copy the most recent nonblank VAR1.&amp;nbsp; It would be faster to combine the first three steps:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test3;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; set test;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; if var2=' ' then delete;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; if var1 ne ' ' then temp=var1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; else var1=temp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; retain temp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; if upcase(compress(var1)) in ('UPDATEDATE', 'GENERICNAME', ... etc.);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;An IF statement (without a THEN result) determines which observations should remain and deletes the rest.&amp;nbsp; And RETAIN holds on to the current value of a variable, even when moving from one observation to the next.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In general, you might need to play with these tools to get the hang of them.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 Mar 2013 21:43:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-requested-regarding-logic-of-SAS-code/m-p/80365#M17298</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2013-03-18T21:43:08Z</dc:date>
    </item>
    <item>
      <title>Re: Help requested regarding logic of SAS code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-requested-regarding-logic-of-SAS-code/m-p/80366#M17299</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for your inputs.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Mar 2013 09:26:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-requested-regarding-logic-of-SAS-code/m-p/80366#M17299</guid>
      <dc:creator>arch</dc:creator>
      <dc:date>2013-03-19T09:26:25Z</dc:date>
    </item>
  </channel>
</rss>

