<?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: creating a table using variables from 2 different data sets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/creating-a-table-using-variables-from-2-different-data-sets/m-p/883917#M349200</link>
    <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;Both dataset have most of the same variable names (column headings) but not all. What is the best way to go about doing this?&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Without you showing us a portion of both data sets, I don't think anyone can answer the question. Data should be provided according to these &lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;examples and instructions&lt;/A&gt;. &lt;FONT color="#FF0000"&gt;Do not provide data in other forms. Do not ignore this paragraph.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#333333"&gt;Also, many of us will not download attachments. Please copy your SAS code as text and paste it into the window that appears when you click on the "little running man" icon.&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 07 Jul 2023 10:12:42 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2023-07-07T10:12:42Z</dc:date>
    <item>
      <title>creating a table using variables from 2 different data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-a-table-using-variables-from-2-different-data-sets/m-p/883878#M349180</link>
      <description>&lt;P&gt;I have created 2 different datasets by importing 2 excel spreadsheets. In dataset A I have active participants and in dataset B I have completed participants. Both completed and active variables are coded as 1 for true, 0 for false.&amp;nbsp; I would like to create a table that will give me the count of active participants by program, count of completed participants by program, then a total of active and complete by program.&amp;nbsp; Both dataset have most of the same variable names (column headings) but not all. What is the best way to go about doing this? I have attempted to merge datasets and sort by program but received a proc tabulate error of "The type of variable is unknown".&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to just add the one variable (or the one variable along with the program variable) to the data set?&amp;nbsp;&lt;/P&gt;&lt;P&gt;or&lt;/P&gt;&lt;P&gt;Is there a way to create one variable from variables in 2 different datasets?&lt;/P&gt;&lt;P&gt;I have sas9.4.&lt;/P&gt;&lt;P&gt;Hope this is enough info.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help!&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jul 2023 02:32:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-a-table-using-variables-from-2-different-data-sets/m-p/883878#M349180</guid>
      <dc:creator>Whitlea</dc:creator>
      <dc:date>2023-07-07T02:32:33Z</dc:date>
    </item>
    <item>
      <title>Re: creating a table using variables from 2 different data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-a-table-using-variables-from-2-different-data-sets/m-p/883917#M349200</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;Both dataset have most of the same variable names (column headings) but not all. What is the best way to go about doing this?&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Without you showing us a portion of both data sets, I don't think anyone can answer the question. Data should be provided according to these &lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;examples and instructions&lt;/A&gt;. &lt;FONT color="#FF0000"&gt;Do not provide data in other forms. Do not ignore this paragraph.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#333333"&gt;Also, many of us will not download attachments. Please copy your SAS code as text and paste it into the window that appears when you click on the "little running man" icon.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jul 2023 10:12:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-a-table-using-variables-from-2-different-data-sets/m-p/883917#M349200</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-07-07T10:12:42Z</dc:date>
    </item>
    <item>
      <title>Re: creating a table using variables from 2 different data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-a-table-using-variables-from-2-different-data-sets/m-p/883969#M349218</link>
      <description>&lt;PRE&gt;&lt;CODE class=""&gt;PROC IMPORT OUT= WORK.active 
            DATAFILE= "C:\Users\Documents\report1" 
            DBMS=EXCEL REPLACE;
     SHEET=Active; 
RUN;

PROC IMPORT OUT= WORK.closed 
            DATAFILE= "C:\Users\Documents\report2" 
            DBMS=EXCEL REPLACE;
     SHEET=complete; 
     
RUN;


Data report1;
set WORK.active;
If Admission_Date &amp;gt; '31MAY2023'd  then active=0;
If Approved_End_Date = ' ' then active=1;
If Approved_End_Date &amp;lt; '31MAY2023'd  then active=0;
If Admission_Date &amp;lt; '31MAY2023'd  AND Approved_End_Date &amp;gt;=  '31MAY2023'd  then active=1;
Else active=0;
run;

Data report2;
set WORK.closed;
If Discharge_Date &amp;gt; '31MAY2023'd  then complete=1;
else complete=0;
Run; 
&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;The 2 variables I want counts of are in different datasets so I think the datasets need to be merged unless there is another way to do this. I would like to have a count of &lt;EM&gt;active&lt;/EM&gt;&amp;nbsp;(from report1) per program and a count of &lt;EM&gt;completed (from report2)&lt;/EM&gt; per program (the program variable is in both datasets).&amp;nbsp; Both variables are coded 1/0, 1 for true, 0 for false. Then I would like to have the total for each program.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The table would look something like this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Program&amp;nbsp; &amp;nbsp; Active&amp;nbsp; &amp;nbsp; &amp;nbsp; Complete&amp;nbsp; &amp;nbsp; Total&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/P&gt;&lt;P&gt;B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;C&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&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;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>Fri, 07 Jul 2023 16:43:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-a-table-using-variables-from-2-different-data-sets/m-p/883969#M349218</guid>
      <dc:creator>Whitlea</dc:creator>
      <dc:date>2023-07-07T16:43:17Z</dc:date>
    </item>
    <item>
      <title>Re: creating a table using variables from 2 different data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-a-table-using-variables-from-2-different-data-sets/m-p/883971#M349219</link>
      <description>&lt;P&gt;I'm sorry but I cannot work with data in screen captures, or SAS code in screen captures. I was very specific about how to provide this information, but you did not follow the instructions. Please follow the instructions provided.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jul 2023 15:51:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-a-table-using-variables-from-2-different-data-sets/m-p/883971#M349219</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-07-07T15:51:52Z</dc:date>
    </item>
    <item>
      <title>Re: creating a table using variables from 2 different data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-a-table-using-variables-from-2-different-data-sets/m-p/883976#M349220</link>
      <description>&lt;P&gt;From your original description it sounded like you just wanted to know how many observations where in each dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But perhaps there is more to it than that?&lt;/P&gt;
&lt;P&gt;If you do not just want the total count then what is it you want a count of?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there any need to combine the two datasets?&amp;nbsp; For what purpose?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does either dataset have a variable that uniquely identifies the PARTICIPANT?&amp;nbsp; or some combination of variables?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is it possible that the same PARTICIPANT could appear in more than one of the datasets?&amp;nbsp; If so what does that mean in terms of the counts you want to create?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jul 2023 16:12:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-a-table-using-variables-from-2-different-data-sets/m-p/883976#M349220</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-07-07T16:12:38Z</dc:date>
    </item>
    <item>
      <title>Re: creating a table using variables from 2 different data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-a-table-using-variables-from-2-different-data-sets/m-p/884024#M349239</link>
      <description>&lt;P&gt;Looks like you have&amp;nbsp;common variable PROGRAM in both datasets.&amp;nbsp; If no other common variables to involve there, you could sort both datasets by PROGRAM and merge, then process data BY GROUP using first/last.variables to calculate group totals.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Eg:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data active;
input program:$1 Active:2;
cards;
a 0
a 1
a 0
b 1
b 0
b 1
c 0
c 1
c 0
;
proc print;run; 

data complete;
input program:$1 Completed:2;
cards;
a 1
a 0
a 1
b 0
b 1
b 0
c 1
c 0
c 1
;
proc print;run; 


data want;
	merge active complete;
	by program;
	retain active_total completed_total;
	if first.program then do;
		active_total=active;
		completed_total=completed;
	end; 
	else do;
		active_total+active;
		completed_total+completed;
	end; 
	if last.program;
	Program_total= sum(active_total,completed_total); 
	drop active completed; 
proc print;run; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 07 Jul 2023 22:01:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-a-table-using-variables-from-2-different-data-sets/m-p/884024#M349239</guid>
      <dc:creator>A_Kh</dc:creator>
      <dc:date>2023-07-07T22:01:17Z</dc:date>
    </item>
  </channel>
</rss>

