<?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: How to convert long numeric ID into multiple variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-long-numeric-ID-into-multiple-variables/m-p/895479#M353810</link>
    <description>&lt;P&gt;Macros not needed here. This can be done with data step statements.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, you say there are "hundreds of families", what would say the 157th family look like in this ID variable? You also say the family number is two digits, so it can't be 157. Please explain this further.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, is the variable named ID numeric or character according to PROC CONTENTS?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 22 Sep 2023 17:24:12 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2023-09-22T17:24:12Z</dc:date>
    <item>
      <title>How to convert long numeric ID into multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-long-numeric-ID-into-multiple-variables/m-p/895477#M353809</link>
      <description>&lt;P&gt;I have a data set with IDs like: 100101, 100102, 201201. The first two numbers indicate location, the second two numbers indicate a family group, and the last two numbers indicate the individual within that location and family group. I need to break these up into variables for the family.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Right now I have this:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data new;&lt;BR /&gt;set original;&lt;BR /&gt;if 100100&amp;lt;id&amp;lt;100200 then family=1;&lt;BR /&gt;if 100200&amp;lt;id&amp;lt;100300 then family=2;&lt;BR /&gt;if 100300&amp;lt;id&amp;lt;100400 then family=3;&lt;/P&gt;&lt;P&gt;etc.&amp;nbsp;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have 2,000 observations and hundreds of families so this method is going to take forever. I'm not very skilled at macros yet, is there a way I can code a macro to process this for me?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Sep 2023 17:18:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-long-numeric-ID-into-multiple-variables/m-p/895477#M353809</guid>
      <dc:creator>taylorcclarkson</dc:creator>
      <dc:date>2023-09-22T17:18:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert long numeric ID into multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-long-numeric-ID-into-multiple-variables/m-p/895479#M353810</link>
      <description>&lt;P&gt;Macros not needed here. This can be done with data step statements.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, you say there are "hundreds of families", what would say the 157th family look like in this ID variable? You also say the family number is two digits, so it can't be 157. Please explain this further.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, is the variable named ID numeric or character according to PROC CONTENTS?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Sep 2023 17:24:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-long-numeric-ID-into-multiple-variables/m-p/895479#M353810</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-09-22T17:24:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert long numeric ID into multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-long-numeric-ID-into-multiple-variables/m-p/895480#M353811</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;length location family individual $2 int $6;
int = put(id,z6.);
location = substr(int,1,2);
family = substr(int,3,2);
individual = substr(int,5,2);
drop int;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 22 Sep 2023 17:26:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-long-numeric-ID-into-multiple-variables/m-p/895480#M353811</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-09-22T17:26:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert long numeric ID into multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-long-numeric-ID-into-multiple-variables/m-p/895481#M353812</link>
      <description>&lt;P&gt;The families reset with each new group, so each group has ~20 families, each labeled from 1-20.&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID variable is numeric.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Sep 2023 17:27:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-long-numeric-ID-into-multiple-variables/m-p/895481#M353812</guid>
      <dc:creator>taylorcclarkson</dc:creator>
      <dc:date>2023-09-22T17:27:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert long numeric ID into multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-long-numeric-ID-into-multiple-variables/m-p/895508#M353820</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/432351"&gt;@taylorcclarkson&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;The families reset with each new group, so each group has ~20 families, each labeled from 1-20.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ID variable is numeric.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I would say that extracting just the family from such a description would be incomplete. Unless you have already figured out and added a GROUP variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: you could likely keep all of the group/family together just using a custom format&lt;/P&gt;
&lt;PRE&gt;data example;
   input id;
datalines;
100101
100102
100103
100201
100202
100203
100204
110101
110102
110201
110202
110203
;

proc format;
picture grpfam 
low-high ='9999' (mult=0.01)
;

proc print data=example;
   format id grpfam.;
run;&lt;/PRE&gt;
&lt;P&gt;The above custom format only displays the first 4 digits of the id. (it shifts the decimal place of the ID variable with the mult and then doesn't display any decimal values by default).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The groups created by formats are honored by most procedures so you can do things like:&lt;/P&gt;
&lt;PRE&gt;proc freq data=example;
   tables id;
   format id grpfam.;
run;&lt;/PRE&gt;
&lt;P&gt;to count family members.&lt;/P&gt;
&lt;P&gt;Or to use the grp/family as a group in a regression or similar procedure.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since formats allow you to work with the formatted values in most places they can be very efficient ways to make different tables, analyses or graphs without having to go back and keep adding variables to the data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And&amp;nbsp; just changing the digit selectors in the format:&lt;/P&gt;
&lt;PRE&gt;proc format;
picture fam 
low-high ='99' (mult=0.01)
;
&lt;/PRE&gt;
&lt;P&gt;will display the 2 digits of the family.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Sep 2023 20:55:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-long-numeric-ID-into-multiple-variables/m-p/895508#M353820</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-09-22T20:55:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert long numeric ID into multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-long-numeric-ID-into-multiple-variables/m-p/895514#M353822</link>
      <description>&lt;P&gt;You can also just use arithmetic to pull out the values.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data new;
  set original;
  individual = mod(id,100);
  family = int(id/100);
  group = int(family/100);
  family = mod(family,100);
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 23 Sep 2023 00:32:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-long-numeric-ID-into-multiple-variables/m-p/895514#M353822</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-09-23T00:32:14Z</dc:date>
    </item>
  </channel>
</rss>

