<?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: seperating variable text, and creating new line in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/seperating-variable-text-and-creating-new-line/m-p/824784#M325756</link>
    <description>Ballardw, your solution to splitting the county name works. I'll try the remaining part tomorrow. Reeza your part almost works. I'm not clear if I indicated that I didn't want the word "County" in the output, just the name of the county.&lt;BR /&gt;&lt;BR /&gt;Thanks both.</description>
    <pubDate>Thu, 21 Jul 2022 20:59:43 GMT</pubDate>
    <dc:creator>geneshackman</dc:creator>
    <dc:date>2022-07-21T20:59:43Z</dc:date>
    <item>
      <title>seperating variable text, and creating new line</title>
      <link>https://communities.sas.com/t5/SAS-Programming/seperating-variable-text-and-creating-new-line/m-p/824772#M325745</link>
      <description>&lt;P&gt;Hi all&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope everyone is healthy!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is part of my data set&lt;/P&gt;
&lt;TABLE width="809"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="155"&gt;Not Hispanic or Latino&lt;/TD&gt;
&lt;TD width="251"&gt;Albany County, NY (36001)&lt;/TD&gt;
&lt;TD width="275"&gt;American Indian or Alaska Native&lt;/TD&gt;
&lt;TD width="64"&gt;1,370&lt;/TD&gt;
&lt;TD width="64"&gt;300&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Not Hispanic or Latino&lt;/TD&gt;
&lt;TD&gt;Albany County, NY (36001)&lt;/TD&gt;
&lt;TD&gt;Asian&lt;/TD&gt;
&lt;TD&gt;62,742&lt;/TD&gt;
&lt;TD&gt;4,520&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Not Hispanic or Latino&lt;/TD&gt;
&lt;TD&gt;Albany County, NY (36001)&lt;/TD&gt;
&lt;TD&gt;Black or African American&lt;/TD&gt;
&lt;TD&gt;116,750&lt;/TD&gt;
&lt;TD&gt;11,993&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Not Hispanic or Latino&lt;/TD&gt;
&lt;TD&gt;Albany County, NY (36001)&lt;/TD&gt;
&lt;TD&gt;Native Hawaiian or Other Pacific Islander&lt;/TD&gt;
&lt;TD&gt;452&lt;/TD&gt;
&lt;TD&gt;12&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Not Hispanic or Latino&lt;/TD&gt;
&lt;TD&gt;Albany County, NY (36001)&lt;/TD&gt;
&lt;TD&gt;White&lt;/TD&gt;
&lt;TD&gt;652,841&lt;/TD&gt;
&lt;TD&gt;137,877&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Not Hispanic or Latino&lt;/TD&gt;
&lt;TD&gt;Albany County, NY (36001)&lt;/TD&gt;
&lt;TD&gt;More than one race&lt;/TD&gt;
&lt;TD&gt;22,848&lt;/TD&gt;
&lt;TD&gt;1,135&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Not Hispanic or Latino&lt;/TD&gt;
&lt;TD&gt;Albany County, NY (36001)&lt;/TD&gt;
&lt;TD&gt;Total&lt;/TD&gt;
&lt;TD&gt;#####&lt;/TD&gt;
&lt;TD&gt;#####&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Not Hispanic or Latino&lt;/TD&gt;
&lt;TD&gt;Allegany County, NY (36003)&lt;/TD&gt;
&lt;TD&gt;American Indian or Alaska Native&lt;/TD&gt;
&lt;TD&gt;295&lt;/TD&gt;
&lt;TD&gt;62&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Not Hispanic or Latino&lt;/TD&gt;
&lt;TD&gt;Allegany County, NY (36003)&lt;/TD&gt;
&lt;TD&gt;Asian&lt;/TD&gt;
&lt;TD&gt;1,701&lt;/TD&gt;
&lt;TD&gt;115&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Not Hispanic or Latino&lt;/TD&gt;
&lt;TD&gt;Allegany County, NY (36003)&lt;/TD&gt;
&lt;TD&gt;Black or African American&lt;/TD&gt;
&lt;TD&gt;1,709&lt;/TD&gt;
&lt;TD&gt;79&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Not Hispanic or Latino&lt;/TD&gt;
&lt;TD&gt;Allegany County, NY (36003)&lt;/TD&gt;
&lt;TD&gt;Native Hawaiian or Other Pacific Islander&lt;/TD&gt;
&lt;TD&gt;38&lt;/TD&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Not Hispanic or Latino&lt;/TD&gt;
&lt;TD&gt;Allegany County, NY (36003)&lt;/TD&gt;
&lt;TD&gt;White&lt;/TD&gt;
&lt;TD&gt;130,012&lt;/TD&gt;
&lt;TD&gt;26,328&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Not Hispanic or Latino&lt;/TD&gt;
&lt;TD&gt;Allegany County, NY (36003)&lt;/TD&gt;
&lt;TD&gt;More than one race&lt;/TD&gt;
&lt;TD&gt;1,632&lt;/TD&gt;
&lt;TD&gt;121&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Not Hispanic or Latino&lt;/TD&gt;
&lt;TD&gt;Allegany County, NY (36003)&lt;/TD&gt;
&lt;TD&gt;Total&lt;/TD&gt;
&lt;TD&gt;#####&lt;/TD&gt;
&lt;TD&gt;26,708&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to make this part "Albany County, NY (countynumber") into two variables&lt;/P&gt;
&lt;P&gt;county name (e.g. "Albany")&lt;/P&gt;
&lt;P&gt;and&amp;nbsp;&lt;/P&gt;
&lt;P&gt;county number (e.g. 36001)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is that possible?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second, one row is "Native Hawaiian or Other Pacific Islander" and another row is "Asian".&lt;/P&gt;
&lt;P&gt;I'd like to add them together to make a row "Asian/Pacific Islander", and then remove the two component rows.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Gene&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jul 2022 20:12:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/seperating-variable-text-and-creating-new-line/m-p/824772#M325745</guid>
      <dc:creator>geneshackman</dc:creator>
      <dc:date>2022-07-21T20:12:15Z</dc:date>
    </item>
    <item>
      <title>Re: seperating variable text, and creating new line</title>
      <link>https://communities.sas.com/t5/SAS-Programming/seperating-variable-text-and-creating-new-line/m-p/824776#M325748</link>
      <description>&lt;P&gt;Not sure if this will scale but based on your post:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;CountyName = scan(variable, 1, ",");
CountyNumber = scan(variable, 2, "()");

race_combined = race;
if race_combined in ('Asian', 'Native ...') then race_combined = 'Asian/Pacific Islander';

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To combine your rows, you'd need to summarize your data - you can use PROC MEANS/SUMMARY for that. The summary stat is most likely sum, but may depend on the data. You didn't include variable names so I made guesses.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jul 2022 20:29:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/seperating-variable-text-and-creating-new-line/m-p/824776#M325748</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-07-21T20:29:01Z</dc:date>
    </item>
    <item>
      <title>Re: seperating variable text, and creating new line</title>
      <link>https://communities.sas.com/t5/SAS-Programming/seperating-variable-text-and-creating-new-line/m-p/824778#M325750</link>
      <description>Thanks Reeza, I forgot. Yes, variable names would be Ethnicity, County, Race, Total, Age65Plus</description>
      <pubDate>Thu, 21 Jul 2022 20:35:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/seperating-variable-text-and-creating-new-line/m-p/824778#M325750</guid>
      <dc:creator>geneshackman</dc:creator>
      <dc:date>2022-07-21T20:35:12Z</dc:date>
    </item>
    <item>
      <title>Re: seperating variable text, and creating new line</title>
      <link>https://communities.sas.com/t5/SAS-Programming/seperating-variable-text-and-creating-new-line/m-p/824781#M325753</link>
      <description>&lt;P&gt;It might be nice to include your existing variable names.&lt;/P&gt;
&lt;P&gt;The county bits can be solved with the SCAN function mostly. The key is setting the exact characters used for delimiters.&lt;/P&gt;
&lt;P&gt;Tranwrd removes the word County from the result. I hope you don't have a "County County, NY ".&lt;/P&gt;
&lt;PRE&gt;data example;
   County="Albany County, NY (36001)";
   length countyname $ 20;
   countyname = tranwrd(scan(county,1,','),'County','');
   countynum  = scan(county,2,'()');
run;&lt;/PRE&gt;
&lt;P&gt;For your second bit about the race coding my preference would be to leave the values as they are and use a custom format to create text for the combined group.&lt;/P&gt;
&lt;PRE&gt;Proc format;
value $myracecode
"Asian","Native Hawaiian or Other Pacific Islander" ="Asian/Pacific Islander"
;
run;&lt;/PRE&gt;
&lt;P&gt;The use the format with the value, example:&lt;/P&gt;
&lt;PRE&gt;Proc freq data=have;
   tables race;
   format race $myracecode. ;
run;&lt;/PRE&gt;
&lt;P&gt;Why a format you may ask. First as soon as you remove or replace the values someone will ask for a report or analysis separating the two, especially as these are standard, more or less, values. So if you remove them then you get to go back in your code and an undo that. With the format just remove the format (or use a different format).&lt;/P&gt;
&lt;P&gt;The groups created by a format will be honored by reporting, analysis and graphing procedures.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A comment: Inclusion of "Total" or similar summary rows inside a data set is not a good idea for many purposes. It is extremely easy to accidentally include the "total" is some other summary, such as a statewide total and get very incorrect results.&lt;/P&gt;
&lt;P&gt;I would almost say this is the result of another procedure's output and would suggest looking if that is the case what the underlying data is.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jul 2022 21:34:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/seperating-variable-text-and-creating-new-line/m-p/824781#M325753</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-07-21T21:34:56Z</dc:date>
    </item>
    <item>
      <title>Re: seperating variable text, and creating new line</title>
      <link>https://communities.sas.com/t5/SAS-Programming/seperating-variable-text-and-creating-new-line/m-p/824782#M325754</link>
      <description>&lt;P&gt;I'm going to assume you can modify the code with the correct variable names.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have issues, post your code, log and explain the issue.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jul 2022 20:44:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/seperating-variable-text-and-creating-new-line/m-p/824782#M325754</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-07-21T20:44:36Z</dc:date>
    </item>
    <item>
      <title>Re: seperating variable text, and creating new line</title>
      <link>https://communities.sas.com/t5/SAS-Programming/seperating-variable-text-and-creating-new-line/m-p/824784#M325756</link>
      <description>Ballardw, your solution to splitting the county name works. I'll try the remaining part tomorrow. Reeza your part almost works. I'm not clear if I indicated that I didn't want the word "County" in the output, just the name of the county.&lt;BR /&gt;&lt;BR /&gt;Thanks both.</description>
      <pubDate>Thu, 21 Jul 2022 20:59:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/seperating-variable-text-and-creating-new-line/m-p/824784#M325756</guid>
      <dc:creator>geneshackman</dc:creator>
      <dc:date>2022-07-21T20:59:43Z</dc:date>
    </item>
    <item>
      <title>Re: seperating variable text, and creating new line</title>
      <link>https://communities.sas.com/t5/SAS-Programming/seperating-variable-text-and-creating-new-line/m-p/824785#M325757</link>
      <description>&lt;P&gt;If you don't want the word COUNTY you'll want to use mine and then substr it to remove the COUNTY. Many counties in my experience do have two or three names, not just one.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or map the county number to the name using one of the datasets from SASMAPS library.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jul 2022 21:05:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/seperating-variable-text-and-creating-new-line/m-p/824785#M325757</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-07-21T21:05:29Z</dc:date>
    </item>
    <item>
      <title>Re: seperating variable text, and creating new line</title>
      <link>https://communities.sas.com/t5/SAS-Programming/seperating-variable-text-and-creating-new-line/m-p/824829#M325778</link>
      <description>&lt;P&gt;Posting data in usable form makes it much easier to suggest solutions. The following code implements the idea of &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt; to use a map dataset:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.CountyFmt;
   set mapsgfk.us_all_attr(keep= id idname rename=(idname = Label));
   length Start $ 10;
   retain FmtName '$CountyName';

   Start = compress(id,, 'kd');

   drop id;
run;

proc format cntlin=work.CountyFmt;
run;

data work.want;
   set work.have;
   
   length CountyName $ 55 CountyNumber $ 10;

   CountyNumber = compress(County,, 'kd');
   CountyName = put(CountyNumber, $CountyName.);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 22 Jul 2022 05:48:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/seperating-variable-text-and-creating-new-line/m-p/824829#M325778</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2022-07-22T05:48:50Z</dc:date>
    </item>
    <item>
      <title>Re: seperating variable text, and creating new line</title>
      <link>https://communities.sas.com/t5/SAS-Programming/seperating-variable-text-and-creating-new-line/m-p/824936#M325822</link>
      <description>&lt;P&gt;For separating out the county name and ID, Ballardw's method worked for me&lt;/P&gt;
&lt;P&gt;countyname = tranwrd(scan(county,1,','),'County','');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'll look at the other part now, collapsing two groups.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jul 2022 15:48:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/seperating-variable-text-and-creating-new-line/m-p/824936#M325822</guid>
      <dc:creator>geneshackman</dc:creator>
      <dc:date>2022-07-22T15:48:35Z</dc:date>
    </item>
  </channel>
</rss>

