<?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: How to add data to a dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-data-to-a-dataset/m-p/780771#M248804</link>
    <description>&lt;P&gt;Expected output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;hsc_id	seq_nbr	prg_type_cd	risk
188789846	1	ACUTE HOSPITAL	SURGICAL
188835206	2	OUTPATIENT FACILITY	SURGICAL1
188985878	1	ACUTE HOSPITAL	SURGICAL2
189414777	3	ACUTE HOSPITAL SURGICAL4	
189414866	1	OUTPATIENT FACILITY	SURGICAL3
189415555	1	OUTPATIENT FACILITY SURGICAL4	
&lt;/LI-CODE&gt;</description>
    <pubDate>Wed, 17 Nov 2021 16:22:34 GMT</pubDate>
    <dc:creator>DanD999</dc:creator>
    <dc:date>2021-11-17T16:22:34Z</dc:date>
    <item>
      <title>How to add data to a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-data-to-a-dataset/m-p/780764#M248799</link>
      <description>&lt;P&gt;The queries that I use for facl and nonfacl may or may not return any rows. Notice that the temp88 query uses a hsc_id and a seq_nbr as the join where as the temp7 query only uses the hsc_id. So right now the last query, temp88, does not update the prg_type_cd and risk columns.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've thought about adding the two blank columns to the mbrs table initially and then using an update in the proc sql, but is there a better, simpler way to do this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;data	  mbrs;
	infile datalines delimiter=',';
	input hsc_id seq_nbr;
	datalines;
188789846,1
188835206,2
188985878,1
189414866,1
189414777,3
189415555,1
;
run;

data	  facl;
	length prg_type_cd risk $ 20;
	infile datalines delimiter=',';
	input hsc_id prg_type_cd $ risk $ ;
	datalines;
188789846,ACUTE HOSPITAL,SURGICAL
188835206,OUTPATIENT FACILITY,SURGICAL1
188985878,ACUTE HOSPITAL,SURGICAL2
189414866,OUTPATIENT FACILITY,SURGICAL3
;
run;

proc sql;
	create table temp7 as
	select mbrs.*, facl.prg_type_cd, facl.risk
	from mbrs
	left join facl
	on facl.hsc_id=mbrs.hsc_id
;
quit;


data	  nonfacl;
	length prg_type_cd risk $ 20;
	infile datalines delimiter=',';
	input hsc_id seq_nbr prg_type_cd $ risk $ ;
	datalines;
189414777,3,ACUTE HOSPITAL,SURGICAL4
189415555,1,OUTPATIENT FACILITY,SURGICAL4
;
run;

proc sql;
	create table temp88 as
	select mbrs.*, nonfacl.prg_type_cd, nonfacl.risk
	from temp7 mbrs
	left join nonfacl
	on nonfacl.hsc_id=mbrs.hsc_id
	and nonfacl.seq_nbr=mbrs.seq_nbr
;
quit;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Nov 2021 15:53:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-data-to-a-dataset/m-p/780764#M248799</guid>
      <dc:creator>DanD999</dc:creator>
      <dc:date>2021-11-17T15:53:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to add data to a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-data-to-a-dataset/m-p/780768#M248803</link>
      <description>Please attach an expected output for better understandning of your issue.</description>
      <pubDate>Wed, 17 Nov 2021 16:10:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-data-to-a-dataset/m-p/780768#M248803</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2021-11-17T16:10:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to add data to a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-data-to-a-dataset/m-p/780771#M248804</link>
      <description>&lt;P&gt;Expected output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;hsc_id	seq_nbr	prg_type_cd	risk
188789846	1	ACUTE HOSPITAL	SURGICAL
188835206	2	OUTPATIENT FACILITY	SURGICAL1
188985878	1	ACUTE HOSPITAL	SURGICAL2
189414777	3	ACUTE HOSPITAL SURGICAL4	
189414866	1	OUTPATIENT FACILITY	SURGICAL3
189415555	1	OUTPATIENT FACILITY SURGICAL4	
&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 17 Nov 2021 16:22:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-data-to-a-dataset/m-p/780771#M248804</guid>
      <dc:creator>DanD999</dc:creator>
      <dc:date>2021-11-17T16:22:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to add data to a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-data-to-a-dataset/m-p/780774#M248805</link>
      <description>&lt;P&gt;"add data to a dataset" is not a normal analysis process.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sounds like you want to make a NEW dataset that has the information from those three input datasets.&lt;/P&gt;
&lt;P&gt;Since the keys are different just use multiple steps. (make sure the sources are sorted by the key variables).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data step1 ;
  merge mbrs facl;
  by hsc_id;
run;

proc print;
 title 'step1';
run;

data step2;
  merge step1 nonfacl;
  by hsc_id seq_nbr;
run;

proc print;
 title 'step2';
run;
title;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 525px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/65839iABDA296962E54E87/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Nov 2021 16:45:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-data-to-a-dataset/m-p/780774#M248805</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-11-17T16:45:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to add data to a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-data-to-a-dataset/m-p/780792#M248810</link>
      <description>&lt;P&gt;You can do it in one data step through the use of hash objects:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set mbrs;
length prg_type_cd risk $ 20 seq_nbr 8;
if _n_ = 1
then do;
  declare hash facl (dataset:"facl");
  facl.definekey("hsc_id");
  facl.definedata("prg_type_cd","risk");
  facl.definedone();
  declare hash nonfacl (dataset:"nonfacl");
  nonfacl.definekey("hsc_id","seq_nbr");
  nonfacl.definedata("prg_type_cd","risk");
  nonfacl.definedone();
end;
rc = facl.find();
rc = nonfacl.find();
drop rc;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 Nov 2021 17:28:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-data-to-a-dataset/m-p/780792#M248810</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-11-17T17:28:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to add data to a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-data-to-a-dataset/m-p/780801#M248814</link>
      <description>&lt;P&gt;I thought that there must be a simpler way. I didn't think of using merge instead of proc sql. Thanks Tom.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Nov 2021 17:51:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-data-to-a-dataset/m-p/780801#M248814</guid>
      <dc:creator>DanD999</dc:creator>
      <dc:date>2021-11-17T17:51:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to add data to a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-data-to-a-dataset/m-p/780803#M248816</link>
      <description>&lt;P&gt;Thanks for an alternative Kurt.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Nov 2021 17:52:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-data-to-a-dataset/m-p/780803#M248816</guid>
      <dc:creator>DanD999</dc:creator>
      <dc:date>2021-11-17T17:52:10Z</dc:date>
    </item>
  </channel>
</rss>

