<?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: Make a variable consistent over the entire dataset in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Make-a-variable-consistent-over-the-entire-dataset/m-p/947170#M42536</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/134532"&gt;@NewUsrStat&lt;/a&gt;, I should also mention that running your DATA step to create DB didn't work.&amp;nbsp;By default, when you reach the end of the line and there are missing values for the remainder of the variables, SAS will continue reading from the next line. Hence the message below: "SAS went to a new line when INPUT statement reached past the end of the line".&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="antonbcristina_0-1728664388204.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/101154i5E5E99C744D9DB4C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="antonbcristina_0-1728664388204.png" alt="antonbcristina_0-1728664388204.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You'll want to add in the option TRUNCOVER like so:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data DB;
  infile cards truncover;
  input ID :$20. Admission :date09. Discharge :date09. Sex $;
  format Admission date9. Discharge date9.;
cards;
0001  13JAN2017 25JAN2017  M
0001  22FEB2018 03MAR2018  
0001  22FEB2018 03MAR2018 
0002  01DEC2016 14DEC2016  F
0002  01DEC2016 14DEC2016  
0002  25DEC2017 02JAN2018 
0002  06JAN2018 09JAN2018  
;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 11 Oct 2024 16:35:28 GMT</pubDate>
    <dc:creator>antonbcristina</dc:creator>
    <dc:date>2024-10-11T16:35:28Z</dc:date>
    <item>
      <title>Make a variable consistent over the entire dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Make-a-variable-consistent-over-the-entire-dataset/m-p/947164#M42533</link>
      <description>&lt;P&gt;Hi guys,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;suppose to have the following dataset:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data DB;
  input ID :$20. Admission :date09. Discharge :date09. Sex;
  format Admission date9. Discharge date9.;
cards;
0001  13JAN2017 25JAN2017  M
0001  22FEB2018 03MAR2018  
0001  22FEB2018 03MAR2018 
0002  01DEC2016 14DEC2016  F
0002  01DEC2016 14DEC2016  
0002  25DEC2017 02JAN2018 
0002  06JAN2018 09JAN2018  
;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is there a way to make consistent the variable sex, in other words to get the following dataset?&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;PRE&gt;&lt;CODE class=" language-sas"&gt;data DB1;
  input ID :$20. Admission :date09. Discharge :date09. Sex;
  format Admission date9. Discharge date9.;
cards;
0001  13JAN2017 25JAN2017  M
0001  22FEB2018 03MAR2018  M 
0001  22FEB2018 03MAR2018  M
0002  01DEC2016 14DEC2016  F
0002  01DEC2016 14DEC2016  F
0002  25DEC2017 02JAN2018  F
0002  06JAN2018 09JAN2018  F
;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that replicated dates are there for a reason.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Oct 2024 16:15:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Make-a-variable-consistent-over-the-entire-dataset/m-p/947164#M42533</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2024-10-11T16:15:58Z</dc:date>
    </item>
    <item>
      <title>Re: Make a variable consistent over the entire dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Make-a-variable-consistent-over-the-entire-dataset/m-p/947167#M42534</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/134532"&gt;@NewUsrStat&lt;/a&gt;, assuming Sex is always non-missing for the first instance of ID, you'll want to create a new variable (New_Sex) that retains the Sex value for all observations for an ID.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data db1;
	retain New_Sex;
	set db;
	by id;

	if first.id then New_Sex=Sex;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Oct 2024 16:31:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Make-a-variable-consistent-over-the-entire-dataset/m-p/947167#M42534</guid>
      <dc:creator>antonbcristina</dc:creator>
      <dc:date>2024-10-11T16:31:05Z</dc:date>
    </item>
    <item>
      <title>Re: Make a variable consistent over the entire dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Make-a-variable-consistent-over-the-entire-dataset/m-p/947169#M42535</link>
      <description>&lt;P&gt;Your first data set does not create a usable data set as 1) Sex is read as numeric, hence all missing and 2) read past the end of the line because of the missing values in the SEX column.&lt;/P&gt;
&lt;P&gt;The $ after Sex on the input statement fixes the first problem, TRUNCOVER on the INFILE the other by stopping reading when running out of values.&lt;/P&gt;
&lt;PRE&gt;data work.DB;
  infile datalines truncover;
  input ID :$20. Admission :date09. Discharge :date09. Sex $;
  format Admission date9. Discharge date9.;
cards;
0001  13JAN2017 25JAN2017  M
0001  22FEB2018 03MAR2018  
0001  22FEB2018 03MAR2018 
0002  01DEC2016 14DEC2016  F
0002  01DEC2016 14DEC2016  
0002  25DEC2017 02JAN2018 
0002  06JAN2018 09JAN2018  
;run;
&lt;/PRE&gt;
&lt;P&gt;One way:&lt;/P&gt;
&lt;PRE&gt;Proc sql;
   create table work.db1 as
   select a.id, a.admission, a.discharge
          ,b.sex
   from   work.db as a
          left join
          (select distinct id,sex from work.db
           where not missing(sex) ) as b
           on a.id=b.id
   ;
quit;&lt;/PRE&gt;
&lt;P&gt;If you data is not in sorted order on input this might change that.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Oct 2024 16:34:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Make-a-variable-consistent-over-the-entire-dataset/m-p/947169#M42535</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-10-11T16:34:38Z</dc:date>
    </item>
    <item>
      <title>Re: Make a variable consistent over the entire dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Make-a-variable-consistent-over-the-entire-dataset/m-p/947170#M42536</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/134532"&gt;@NewUsrStat&lt;/a&gt;, I should also mention that running your DATA step to create DB didn't work.&amp;nbsp;By default, when you reach the end of the line and there are missing values for the remainder of the variables, SAS will continue reading from the next line. Hence the message below: "SAS went to a new line when INPUT statement reached past the end of the line".&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="antonbcristina_0-1728664388204.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/101154i5E5E99C744D9DB4C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="antonbcristina_0-1728664388204.png" alt="antonbcristina_0-1728664388204.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You'll want to add in the option TRUNCOVER like so:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data DB;
  infile cards truncover;
  input ID :$20. Admission :date09. Discharge :date09. Sex $;
  format Admission date9. Discharge date9.;
cards;
0001  13JAN2017 25JAN2017  M
0001  22FEB2018 03MAR2018  
0001  22FEB2018 03MAR2018 
0002  01DEC2016 14DEC2016  F
0002  01DEC2016 14DEC2016  
0002  25DEC2017 02JAN2018 
0002  06JAN2018 09JAN2018  
;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Oct 2024 16:35:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Make-a-variable-consistent-over-the-entire-dataset/m-p/947170#M42536</guid>
      <dc:creator>antonbcristina</dc:creator>
      <dc:date>2024-10-11T16:35:28Z</dc:date>
    </item>
    <item>
      <title>Re: Make a variable consistent over the entire dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Make-a-variable-consistent-over-the-entire-dataset/m-p/947176#M42537</link>
      <description>&lt;P&gt;Not sure what you want to do when there are two different values.&lt;/P&gt;
&lt;P&gt;But a simple merge of dataset with itself should work fine.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data DB;
  input ID :$20. Admission :date. Discharge :date. Sex $;
  format Admission Discharge date9.;
cards;
0001  13JAN2017 25JAN2017  M
0001  22FEB2018 03MAR2018  .
0001  22FEB2018 03MAR2018  .
0002  01DEC2016 14DEC2016  F
0002  01DEC2016 14DEC2016  .
0002  25DEC2017 02JAN2018  .
0002  06JAN2018 09JAN2018  .
;

data want ;
  merge db(where=(not missing(sex))) db(drop=sex);
  by id;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;Obs     ID     Admission    Discharge    Sex

 1     0001    13JAN2017    25JAN2017     M
 2     0001    22FEB2018    03MAR2018     M
 3     0001    22FEB2018    03MAR2018     M
 4     0002    01DEC2016    14DEC2016     F
 5     0002    01DEC2016    14DEC2016     F
 6     0002    25DEC2017    02JAN2018     F
 7     0002    06JAN2018    09JAN2018     F
&lt;/PRE&gt;</description>
      <pubDate>Fri, 11 Oct 2024 18:02:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Make-a-variable-consistent-over-the-entire-dataset/m-p/947176#M42537</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-10-11T18:02:16Z</dc:date>
    </item>
    <item>
      <title>Re: Make a variable consistent over the entire dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Make-a-variable-consistent-over-the-entire-dataset/m-p/947205#M42539</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data DB;
  input ID :$20. Admission :date. Discharge :date. Sex $;
  format Admission Discharge date9.;
cards;
0001  13JAN2017 25JAN2017  M
0001  22FEB2018 03MAR2018  .
0001  22FEB2018 03MAR2018  .
0002  01DEC2016 14DEC2016  F
0002  01DEC2016 14DEC2016  .
0002  25DEC2017 02JAN2018  .
0002  06JAN2018 09JAN2018  .
;

data want ;
  update db(obs=0) db;
  by id;
  output;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 12 Oct 2024 07:07:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Make-a-variable-consistent-over-the-entire-dataset/m-p/947205#M42539</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-10-12T07:07:37Z</dc:date>
    </item>
  </channel>
</rss>

