<?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 How to merge data sets that are optional (may be missing)  Using SAS 9.2 (TS2M3) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-merge-data-sets-that-are-optional-may-be-missing-Using/m-p/556049#M154832</link>
    <description>&lt;P&gt;I am trying to merge data sets that may or may not exist.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data visits;&lt;BR /&gt;set sc_visit bl_visit v01_visit v02_visit pw;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If the subjects have not reached the V02 visit then v02_visit data set will not exist.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I do this combination of data sets if a data set may or may not exist?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;More complete documentation is attached.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This odd combination is because I am pulling data sets from REDCap which provides one record per event.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR MESSAGE:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1672 data visits;&lt;BR /&gt;1673 set sc_visit bl_visit v01_visit v02_visit pw;&lt;BR /&gt;ERROR: Variable coord has been defined as both character and numeric.&lt;BR /&gt;1674 run;&lt;/P&gt;</description>
    <pubDate>Fri, 03 May 2019 19:00:13 GMT</pubDate>
    <dc:creator>tanya_henderson</dc:creator>
    <dc:date>2019-05-03T19:00:13Z</dc:date>
    <item>
      <title>How to merge data sets that are optional (may be missing)  Using SAS 9.2 (TS2M3)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-merge-data-sets-that-are-optional-may-be-missing-Using/m-p/556049#M154832</link>
      <description>&lt;P&gt;I am trying to merge data sets that may or may not exist.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data visits;&lt;BR /&gt;set sc_visit bl_visit v01_visit v02_visit pw;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If the subjects have not reached the V02 visit then v02_visit data set will not exist.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I do this combination of data sets if a data set may or may not exist?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;More complete documentation is attached.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This odd combination is because I am pulling data sets from REDCap which provides one record per event.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR MESSAGE:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1672 data visits;&lt;BR /&gt;1673 set sc_visit bl_visit v01_visit v02_visit pw;&lt;BR /&gt;ERROR: Variable coord has been defined as both character and numeric.&lt;BR /&gt;1674 run;&lt;/P&gt;</description>
      <pubDate>Fri, 03 May 2019 19:00:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-merge-data-sets-that-are-optional-may-be-missing-Using/m-p/556049#M154832</guid>
      <dc:creator>tanya_henderson</dc:creator>
      <dc:date>2019-05-03T19:00:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge data sets that are optional (may be missing)  Using SAS 9.2 (TS2M3)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-merge-data-sets-that-are-optional-may-be-missing-Using/m-p/556073#M154851</link>
      <description>&lt;P&gt;ERROR: Variable coord has been defined as both character and numeric.&lt;/P&gt;
&lt;P&gt;define coord as character or numeric in all datasets containing coord&lt;/P&gt;</description>
      <pubDate>Fri, 03 May 2019 19:32:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-merge-data-sets-that-are-optional-may-be-missing-Using/m-p/556073#M154851</guid>
      <dc:creator>VDD</dc:creator>
      <dc:date>2019-05-03T19:32:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge data sets that are optional (may be missing)  Using SAS 9.2 (TS2M3)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-merge-data-sets-that-are-optional-may-be-missing-Using/m-p/556074#M154852</link>
      <description>Did you read these in from Excel, a CSV, or directly from RedCap? Single record for event, is common practice.</description>
      <pubDate>Fri, 03 May 2019 19:32:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-merge-data-sets-that-are-optional-may-be-missing-Using/m-p/556074#M154852</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-05-03T19:32:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge data sets that are optional (may be missing)  Using SAS 9.2 (TS2M3)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-merge-data-sets-that-are-optional-may-be-missing-Using/m-p/556079#M154856</link>
      <description>&lt;P&gt;I am reading these in from a CSV. The main csv files are the health and screen data sets.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 May 2019 19:35:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-merge-data-sets-that-are-optional-may-be-missing-Using/m-p/556079#M154856</guid>
      <dc:creator>tanya_henderson</dc:creator>
      <dc:date>2019-05-03T19:35:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge data sets that are optional (may be missing)  Using SAS 9.2 (TS2M3)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-merge-data-sets-that-are-optional-may-be-missing-Using/m-p/556082#M154859</link>
      <description>coord is numeric in all data sets. The issue becomes character if the data set doesn't exist.</description>
      <pubDate>Fri, 03 May 2019 19:36:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-merge-data-sets-that-are-optional-may-be-missing-Using/m-p/556082#M154859</guid>
      <dc:creator>tanya_henderson</dc:creator>
      <dc:date>2019-05-03T19:36:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge data sets that are optional (may be missing)  Using SAS 9.2 (TS2M3)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-merge-data-sets-that-are-optional-may-be-missing-Using/m-p/556083#M154860</link>
      <description>Guessing you used PROC IMPORT? I think you're going to need to go back, read them all in with data steps and ensure your types are read in correctly. PROC IMPORT makes guesses at types and sometimes it's wrong, which is why you get what's happening above. &lt;BR /&gt;&lt;BR /&gt;You could try add GUESSINGROWS=MAX to your PROC IMPORT but that's not a guarantee by any means.</description>
      <pubDate>Fri, 03 May 2019 19:36:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-merge-data-sets-that-are-optional-may-be-missing-Using/m-p/556083#M154860</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-05-03T19:36:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge data sets that are optional (may be missing)  Using SAS 9.2 (TS2M3)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-merge-data-sets-that-are-optional-may-be-missing-Using/m-p/556086#M154862</link>
      <description>&lt;P&gt;The issue is that some events have not yet occurred. There are no V01 visits that meet the criteria. So, when I try to merge in the V01_visit data set to the final results, it causes errors.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data visits;&lt;BR /&gt;set sc_visit bl_visit /*v01_visit v02_visit pw*/;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I comment out the data sets as above, the report works fine. How do I account for data that may not exist?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am looking for something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data visits;&lt;BR /&gt;set sc_visit bl_visit&amp;nbsp; %if (exists(v01_visit))&amp;nbsp; %if (exists(v02_visit)) %if (exists(pw));&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 03 May 2019 19:43:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-merge-data-sets-that-are-optional-may-be-missing-Using/m-p/556086#M154862</guid>
      <dc:creator>tanya_henderson</dc:creator>
      <dc:date>2019-05-03T19:43:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge data sets that are optional (may be missing)  Using SAS 9.2 (TS2M3)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-merge-data-sets-that-are-optional-may-be-missing-Using/m-p/556091#M154866</link>
      <description>&lt;P&gt;&amp;nbsp;Is there a pattern to the naming structure of the files you'd like to combine that allows you to uniquely identify those data sets?&lt;/P&gt;
&lt;P&gt;If it catches the 0 ones that's fine. If there is, you can dynamically generate the list of names. Because you're on such an old version I don't think you can use shortcut lists. SAS 9.2 is really, really old by the way, if you have any options to push for an upgrade do so.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you're in Academia, SAS UE is freely available.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/39434"&gt;@tanya_henderson&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;The issue is that some events have not yet occurred. There are no V01 visits that meet the criteria. So, when I try to merge in the V01_visit data set to the final results, it causes errors.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data visits;&lt;BR /&gt;set sc_visit bl_visit /*v01_visit v02_visit pw*/;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I comment out the data sets as above, the report works fine. How do I account for data that may not exist?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am looking for something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data visits;&lt;BR /&gt;set sc_visit bl_visit&amp;nbsp; %if (exists(v01_visit))&amp;nbsp; %if (exists(v02_visit)) %if (exists(pw));&lt;BR /&gt;run;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 May 2019 19:50:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-merge-data-sets-that-are-optional-may-be-missing-Using/m-p/556091#M154866</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-05-03T19:50:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge data sets that are optional (may be missing)  Using SAS 9.2 (TS2M3)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-merge-data-sets-that-are-optional-may-be-missing-Using/m-p/556128#M154878</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/39434"&gt;@tanya_henderson&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am trying to merge data sets that may or may not exist.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data visits;&lt;BR /&gt;set sc_visit bl_visit v01_visit v02_visit pw;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the subjects have not reached the V02 visit then v02_visit data set will not exist.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How do I do this combination of data sets if a data set may or may not exist?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;More complete documentation is attached.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This odd combination is because I am pulling data sets from REDCap which provides one record per event.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ERROR MESSAGE:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1672 data visits;&lt;BR /&gt;1673 set sc_visit bl_visit v01_visit v02_visit pw;&lt;BR /&gt;ERROR: Variable coord has been defined as both character and numeric.&lt;BR /&gt;1674 run;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If the actual concern is getting files that exist to set together when you don't know which ones actually exist you have two basic approaches: 1) something that tests the existence of the data before placing the name on the set statement which might look something like&lt;/P&gt;
&lt;PRE&gt;data _null_;
   length namestr $ 100;
   if exist('work.sc_visit') then namestr= 'work.sc_visit';
   if exist('work.bl_visit') then namestr = catx(' ',namestr,'work.bl_visit');
   if exist('work.v02_visit') then namestr = catx(' ',namestr,'work.v02_visit');
   if exist('work.pw') then namestr = catx(' ',namestr,'work.pw');
   call execute ('data visits; set');
   call execute (namestr);
   call execute (' ; run;');
run;&lt;/PRE&gt;
&lt;P&gt;Or similar approach with macros.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the question is your data incompatibility you need to go back to your data read steps which appear to have been removed from the code given the comments and header:&lt;/P&gt;
&lt;PRE&gt;/*
## PROGRAM NAME: missing_assess.sas
##       AUTHOR: Tanya Henderson
##         DATE: November 2018
##  DESCRIPTION: import csv export from redcap
##
*/


proc sql; 
create table sc_visit as select h.guid,'SC' as visit , h._compltyn , h._visstat_com, s._coord as coord
from health h left join screen s on h.guid = s._guid and h._redcap_event_name = s._redcap_event_name  and h._compltyn = 0 and h._redcap_event_name = 'screening_arm_1' order by guid; 

create table bl_visit as select h.guid,'BL' as visit , h._compltyn , h._visstat_com, s._bl_coord as coord
from health h left join health s on h.guid = s.guid and h._compltyn = 0 and h._redcap_event_name = 'baseline_arm_1' and s._redcap_event_name ='baseline_pre_visit_arm_1' order by guid; 

create table v01_visit as select h.guid,'V01' as visit , h._compltyn , h._visstat_com, s._v01_coord as coord
from health h left join health s on h.guid = s.guid and h._compltyn = 0 and h._redcap_event_name = 'month_12_arm_1' and s._redcap_event_name ='month_12_pre_visit_arm_1' order by guid; 

create table v02_visit as select h.guid,'V02' as visit , h._compltyn , h._visstat_com, s._v02_coord as coord
from health h left join health s on h.guid = s.guid and h._compltyn = 0 and h._redcap_event_name = 'month_24_arm_1' and s._redcap_event_name ='month_24_pre_visit_arm_1' order by guid; 

create table pw as select guid,'PW' as visit , _compltyn , _visstat_com, 0 as coord
from health where _redcap_event_name = 'premature_withdraw_arm_1' and _compltyn = 0 order by guid; 
quit; &lt;/PRE&gt;
&lt;P&gt;Your comment says "import csv" but there is absolutely no code that does such. One suspects Proc Import which makes separate guesses for each file read.&lt;/P&gt;</description>
      <pubDate>Fri, 03 May 2019 22:47:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-merge-data-sets-that-are-optional-may-be-missing-Using/m-p/556128#M154878</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-05-03T22:47:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge data sets that are optional (may be missing)  Using SAS 9.2 (TS2M3)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-merge-data-sets-that-are-optional-may-be-missing-Using/m-p/556141#M154887</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/39434"&gt;@tanya_henderson&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could query the dictionary tables and populate a macro variable with data sets that actually exist. You then use this macro variable in your set statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sc_visit v02_Visit;
  stop;
run;

%let ds_list=;
proc sql;
  select memname into :ds_list separated by ' '
  from dictionary.tables
  where 
    libname='WORK'
    and memname in ('SC_VISIT', 'BL_VISIT', 'V01_VISIT', 'V02_VISIT', 'PW')
  ;
quit;
%put &amp;amp;=ds_list;

data want;
  set &amp;amp;ds_list;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 04 May 2019 03:28:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-merge-data-sets-that-are-optional-may-be-missing-Using/m-p/556141#M154887</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-05-04T03:28:08Z</dc:date>
    </item>
  </channel>
</rss>

