<?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: multiple lines of data for each subject in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/multiple-lines-of-data-for-each-subject/m-p/826177#M35264</link>
    <description>&lt;P&gt;It is not clear in what form your data is now.&amp;nbsp; You mentioned EXCEL and then show code using INFILE which is not valid for reading a binary file like an Excel workbook.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let's assume you actually have an EXCEL file and have converted it into a SAS dataset using PROC IMPORT.&lt;/P&gt;
&lt;P&gt;Let's also assume you have a variable like SUBJID_ID that is non-missing on every observation that ca be used to group the data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In that case you could treat the whole file like a series of transactions using the UPDATE statement.&amp;nbsp; That will ignore missing values on the transaction records to that the existing value of the variable is not replaced.&amp;nbsp; So essentially values will be carried forward until a non-missing value appears for that variable.&amp;nbsp; If there are variables that you do not want carried forward the add them to the KEEP= option on the extra SET statement.&lt;/P&gt;
&lt;P&gt;So here is an example using HAVE as the name of the existing dataset, SUBJECT_ID as the key variable, and VISIT_DATE as an example of a variable where you do not want carried forward.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  update have(obs=0) have;
  by subject_id;
  set have(keep=visit_date);
  output;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 29 Jul 2022 15:07:33 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-07-29T15:07:33Z</dc:date>
    <item>
      <title>multiple lines of data for each subject</title>
      <link>https://communities.sas.com/t5/New-SAS-User/multiple-lines-of-data-for-each-subject/m-p/826174#M35262</link>
      <description>&lt;P&gt;I have data in an excel file that has ~80 variables starting with N, subject ID, deceased.....&amp;nbsp; There are multiple lines for subject ID as each follow up visit is added in another row and aligned under the 'follow up visit' variable.&amp;nbsp; My issue now is when I'm running reports, the number of "missing" is much higher than it should be because it is counting every repeated subject_id as missing.&amp;nbsp; For example, subject id AMC001 below, is showing sex is missing 4 times.&amp;nbsp; How can I get says to only look at the first subject id and ignore the rest if they are the same subject_id? I tried truncover without an input statement because I have ~80 variables and didn't want to list them all. I figured there has to be an easier way.&lt;/P&gt;&lt;PRE&gt;variables	N	subject_id	Deceased	Reason_for_Death	Sex	Ethnicity
	       12	   008IGG	        0		                  1	 
	       13	   009IGG	        0		                  1	 
	       14	   AMC001	        0		                  0           5
		          AMC001				
		          AMC001				
		          AMC001				
		          AMC001&lt;BR /&gt;&lt;BR /&gt;data=datasets.redcap_pde1; &lt;BR /&gt;Infile miss truncover;&lt;BR /&gt;run;				&lt;/PRE&gt;</description>
      <pubDate>Fri, 29 Jul 2022 14:58:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/multiple-lines-of-data-for-each-subject/m-p/826174#M35262</guid>
      <dc:creator>kristiepauly</dc:creator>
      <dc:date>2022-07-29T14:58:42Z</dc:date>
    </item>
    <item>
      <title>Re: multiple lines of data for each subject</title>
      <link>https://communities.sas.com/t5/New-SAS-User/multiple-lines-of-data-for-each-subject/m-p/826175#M35263</link>
      <description>&lt;P&gt;Once you read this monstrosity of an Excel file into SAS, you can create a new data set using only the first record for each subject_id and then do your statistics on this new data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    by subject_id;
    if first.subject_id;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 29 Jul 2022 15:02:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/multiple-lines-of-data-for-each-subject/m-p/826175#M35263</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-07-29T15:02:16Z</dc:date>
    </item>
    <item>
      <title>Re: multiple lines of data for each subject</title>
      <link>https://communities.sas.com/t5/New-SAS-User/multiple-lines-of-data-for-each-subject/m-p/826177#M35264</link>
      <description>&lt;P&gt;It is not clear in what form your data is now.&amp;nbsp; You mentioned EXCEL and then show code using INFILE which is not valid for reading a binary file like an Excel workbook.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let's assume you actually have an EXCEL file and have converted it into a SAS dataset using PROC IMPORT.&lt;/P&gt;
&lt;P&gt;Let's also assume you have a variable like SUBJID_ID that is non-missing on every observation that ca be used to group the data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In that case you could treat the whole file like a series of transactions using the UPDATE statement.&amp;nbsp; That will ignore missing values on the transaction records to that the existing value of the variable is not replaced.&amp;nbsp; So essentially values will be carried forward until a non-missing value appears for that variable.&amp;nbsp; If there are variables that you do not want carried forward the add them to the KEEP= option on the extra SET statement.&lt;/P&gt;
&lt;P&gt;So here is an example using HAVE as the name of the existing dataset, SUBJECT_ID as the key variable, and VISIT_DATE as an example of a variable where you do not want carried forward.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  update have(obs=0) have;
  by subject_id;
  set have(keep=visit_date);
  output;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 29 Jul 2022 15:07:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/multiple-lines-of-data-for-each-subject/m-p/826177#M35264</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-07-29T15:07:33Z</dc:date>
    </item>
    <item>
      <title>Re: multiple lines of data for each subject</title>
      <link>https://communities.sas.com/t5/New-SAS-User/multiple-lines-of-data-for-each-subject/m-p/826183#M35265</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/344524"&gt;@kristiepauly&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have data in an excel file that has ~80 variables starting with N, subject ID, deceased.....&amp;nbsp; There are multiple lines for subject ID as each follow up visit is added in another row and aligned under the 'follow up visit' variable.&amp;nbsp; My issue now is when I'm running reports, the number of "missing" is much higher than it should be because it is counting every repeated subject_id as missing.&amp;nbsp; For example, subject id AMC001 below, is showing sex is missing 4 times.&amp;nbsp; How can I get says to only look at the first subject id and ignore the rest if they are the same subject_id? I tried truncover without an input statement because I have ~80 variables and didn't want to list them all. I figured there has to be an easier way.&lt;/P&gt;
&lt;PRE&gt;variables	N	subject_id	Deceased	Reason_for_Death	Sex	Ethnicity
	       12	   008IGG	        0		                  1	 
	       13	   009IGG	        0		                  1	 
	       14	   AMC001	        0		                  0           5
		          AMC001				
		          AMC001				
		          AMC001				
		          AMC001&lt;BR /&gt;&lt;BR /&gt;data=datasets.redcap_pde1; &lt;BR /&gt;Infile miss truncover;&lt;BR /&gt;run;				&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;UL&gt;
&lt;LI&gt;No = sign in data step statement required for this&lt;/LI&gt;
&lt;LI&gt;Import Excel files with PROC IMPORT not a data step&lt;/LI&gt;
&lt;LI&gt;Import CSV files with a data step or proc import&lt;/LI&gt;
&lt;LI&gt;If you have a large file you do have to list all the variables and types, use the code generated from proc import (from the log) to make this quicker but if you're setting up a repeatable process you definitely want to use a data step not proc import. Proc import guesses at types and not always correctly so you can end up with issues.&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Fri, 29 Jul 2022 16:10:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/multiple-lines-of-data-for-each-subject/m-p/826183#M35265</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-07-29T16:10:43Z</dc:date>
    </item>
    <item>
      <title>Re: multiple lines of data for each subject</title>
      <link>https://communities.sas.com/t5/New-SAS-User/multiple-lines-of-data-for-each-subject/m-p/826185#M35266</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;Sorry, that was unclear.&amp;nbsp; Your assumptions were correct. The original data was an xlsx file and I imported to SAS. I tried your code and then ran a proc freq on MRI's but I'm still showing 471 'missing' . My total N is 116, so it is still counting the multiple entries for each subject_id.&lt;/P&gt;&lt;PRE&gt;data work.PDE_by_subjectid;
  update datasets.REDCap_PDE0(obs=0)datasets.REDCap_PDE0;
  by subject_id;
  set datasets.REDCap_PDE0; *(keep=redcap_event_name);
  output;
run;

*MRI performed;
Proc freq data=work.PDE_by_subjectid;
	tables MRI_performed /missing;
	format mri_performed $mri_performed.;
run;&lt;BR /&gt;
*RESULTS;
The FREQ Procedure
MRI performed
mri_performed	Frequency	Percent	Cum Frequency	Cum Percent
 	           471	         80.79	      471	       80.79
No	            14	          2.40	      485	       83.19
Yes	            98	          16.81	      583	      100.00&lt;/PRE&gt;</description>
      <pubDate>Fri, 29 Jul 2022 16:13:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/multiple-lines-of-data-for-each-subject/m-p/826185#M35266</guid>
      <dc:creator>kristiepauly</dc:creator>
      <dc:date>2022-07-29T16:13:15Z</dc:date>
    </item>
    <item>
      <title>Re: multiple lines of data for each subject</title>
      <link>https://communities.sas.com/t5/New-SAS-User/multiple-lines-of-data-for-each-subject/m-p/826215#M35269</link>
      <description>&lt;P&gt;Try it without that extra SET and see if you like the results.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The point I was trying to make by including is that it might be that you only want to carry forward the non-missing values on SOME of the variables, like SEX, and not others. Having the extra SET statement re-read ALL of the variables like you did completely undoes anything the UPDATE statement might have done to carry forward values.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jul 2022 19:34:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/multiple-lines-of-data-for-each-subject/m-p/826215#M35269</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-07-29T19:34:47Z</dc:date>
    </item>
  </channel>
</rss>

