<?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: Expand drops character variables? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Expand-drops-character-variables/m-p/85506#M24452</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It makes sense that proc expand won't propagate character vars, since (unlike step) most methods intrinsically require a numeric value as input to the various SPLINE, JOIN, AGGREGATE methods.&amp;nbsp; You could recode the character values into numeric prior to EXPAND, but otherwise you'll have to run a DATA step merging INPUT character vars with OUTPUT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Since you're using STEP, you probably want LOCF (last observation carried forward) for the character variables.&amp;nbsp; This should work (where CVAR1 CVAR2 are names of character variables &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; merge output&amp;nbsp; input (keep=time cvar1 cvar2);&lt;BR /&gt;&amp;nbsp; by time;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array cvars {*} $200&amp;nbsp; cvar1 cvar2;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array locf {2} $200 _temporary_;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do _N_=1 to dim(cvars);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; locf{_N_} = coalescec(cvars{_N_},locf{_N_});&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; cvars{_N_} = locf{_N_};&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;BTW, if you don't know in advance the number of variables in the CVARS, but it's never more than, say, 100, you could just declare the LOCF array to have 100 elements.&amp;nbsp; Also, this program doesn't require all the character vars to have the same length, but it does assume none are longer than 200 byters.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 07 Aug 2012 13:21:52 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2012-08-07T13:21:52Z</dc:date>
    <item>
      <title>Expand drops character variables?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Expand-drops-character-variables/m-p/85505#M24451</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am trying to expand some data by the second to fill missing values. However, the input data has a couple of character variables that do not survive the procedure.&amp;nbsp; It drops everything but the numeric variables.&amp;nbsp; I would like to keep the character variables using the same step method.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any suggestions would be greatly appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; proc expand data=input out=output to=second method=step;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; id TIME;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Aug 2012 20:49:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Expand-drops-character-variables/m-p/85505#M24451</guid>
      <dc:creator>sma11s101</dc:creator>
      <dc:date>2012-08-06T20:49:05Z</dc:date>
    </item>
    <item>
      <title>Re: Expand drops character variables?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Expand-drops-character-variables/m-p/85506#M24452</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It makes sense that proc expand won't propagate character vars, since (unlike step) most methods intrinsically require a numeric value as input to the various SPLINE, JOIN, AGGREGATE methods.&amp;nbsp; You could recode the character values into numeric prior to EXPAND, but otherwise you'll have to run a DATA step merging INPUT character vars with OUTPUT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Since you're using STEP, you probably want LOCF (last observation carried forward) for the character variables.&amp;nbsp; This should work (where CVAR1 CVAR2 are names of character variables &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; merge output&amp;nbsp; input (keep=time cvar1 cvar2);&lt;BR /&gt;&amp;nbsp; by time;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array cvars {*} $200&amp;nbsp; cvar1 cvar2;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array locf {2} $200 _temporary_;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do _N_=1 to dim(cvars);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; locf{_N_} = coalescec(cvars{_N_},locf{_N_});&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; cvars{_N_} = locf{_N_};&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;BTW, if you don't know in advance the number of variables in the CVARS, but it's never more than, say, 100, you could just declare the LOCF array to have 100 elements.&amp;nbsp; Also, this program doesn't require all the character vars to have the same length, but it does assume none are longer than 200 byters.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Aug 2012 13:21:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Expand-drops-character-variables/m-p/85506#M24452</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2012-08-07T13:21:52Z</dc:date>
    </item>
    <item>
      <title>Re: Expand drops character variables?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Expand-drops-character-variables/m-p/85507#M24453</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That worked perfectly!&amp;nbsp; Thank you so much for your help. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For future reference if anyone else uses this, the 2 in locf{2} should be changed to match the number of cvars you have.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Aug 2012 15:16:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Expand-drops-character-variables/m-p/85507#M24453</guid>
      <dc:creator>sma11s101</dc:creator>
      <dc:date>2012-08-07T15:16:56Z</dc:date>
    </item>
  </channel>
</rss>

