<?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 variable from three others in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-from-three-others/m-p/597146#M172027</link>
    <description>&lt;P&gt;Evidently, these variables are all numeric:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;state_flips&lt;/LI&gt;
&lt;LI&gt;geostr_samp&lt;/LI&gt;
&lt;LI&gt;denstr_samp&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To create a character string out of all these, you would use (in a DATA step):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ststr = put(state_flips, z2.) || put(geostr_samp, z2.) || put(denstr_samp, 1.);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 17 Oct 2019 02:15:57 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2019-10-17T02:15:57Z</dc:date>
    <item>
      <title>Creating a variable from three others</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-from-three-others/m-p/597144#M172026</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am working with a nationally representative data (three waves). The stratum (ststr) variable is not available for one wave, which I need to create. Here is what I got from the person who responded to my inquiry about the missing variable:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="Default"&gt;&lt;SPAN style="font-size: 10.5pt;"&gt;"STSTR is a five digit number that combines the values for state_flips (first two characters), geostrs_samp (third and fourth character), and denstrs_samp (final character). &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.5pt;"&gt;You need to covert state_flips, geostrs_samp, denstrs_samp into character variables first. Please add “0” to single digit number if state_flips or geostrs_samp only have one digit. For example, state_flips = 1, then add 0 at beginning. It should be 01. &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.5pt;"&gt;After combining three values together, you could either convert it back a numeric variable or keep it as a character variable."&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="Default"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="Default"&gt;&lt;SPAN style="font-size: 10.5pt;"&gt;I am not sure how to do these steps. I found the code below that allows me to break up a variable into two and extract certain characters into each of the new variables. But I could not find anything that will help me create the ststr variable. If you can also help me with adding "0" to the one-digit variables, I would greatly appreciate it. Please help.&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="Default"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="Default"&gt;&lt;SPAN style="font-size: 10.5pt;"&gt;data pieces_parts;&lt;BR /&gt;input id $ 1-9;&lt;BR /&gt;length state $ 2;&lt;BR /&gt;state = substr(id,1,2);&lt;BR /&gt;num = input(substr(id,7,3),3.);&lt;BR /&gt;datalines;&lt;BR /&gt;NYXXXX123&lt;BR /&gt;NJ1234567&lt;BR /&gt;;&lt;BR /&gt;proc print data= pieces_parts noobs;&lt;BR /&gt;title "Listing of Data Set PIECES_PARTS";&lt;BR /&gt;run;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2019 01:58:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-from-three-others/m-p/597144#M172026</guid>
      <dc:creator>sherineeltoukhy</dc:creator>
      <dc:date>2019-10-17T01:58:47Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a variable from three others</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-from-three-others/m-p/597146#M172027</link>
      <description>&lt;P&gt;Evidently, these variables are all numeric:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;state_flips&lt;/LI&gt;
&lt;LI&gt;geostr_samp&lt;/LI&gt;
&lt;LI&gt;denstr_samp&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To create a character string out of all these, you would use (in a DATA step):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ststr = put(state_flips, z2.) || put(geostr_samp, z2.) || put(denstr_samp, 1.);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Oct 2019 02:15:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-from-three-others/m-p/597146#M172027</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-10-17T02:15:57Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a variable from three others</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-from-three-others/m-p/597148#M172029</link>
      <description>PUT() converts numbers to characters. &lt;BR /&gt;Zd formats displays your numeric data with leading zero. &lt;BR /&gt;&lt;BR /&gt;CATT() will concatenate the variables without any extraneous spaces or padding, because you can often get them added in when using other methods.</description>
      <pubDate>Thu, 17 Oct 2019 02:23:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-from-three-others/m-p/597148#M172029</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-10-17T02:23:36Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a variable from three others</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-from-three-others/m-p/597400#M172127</link>
      <description>&lt;P&gt;Are you sure that the statement was "state flips" not "state fips"? FIPS is a standard coding system, Federal Information Processin Standards.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS even has functions that use the FIPS coding such as Pipstate, Fipname, Fipnamel, Stfips, that convert Fips codes to state names or state abbreviations to Fip values.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2019 15:52:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-from-three-others/m-p/597400#M172127</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-10-17T15:52:26Z</dc:date>
    </item>
  </channel>
</rss>

