<?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 concatenate 2 character vars where there are multiple choices for each in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/concatenate-2-character-vars-where-there-are-multiple-choices/m-p/911649#M359473</link>
    <description>&lt;P&gt;Hello SAS community,&lt;/P&gt;
&lt;P&gt;I successfully imported an excel sheet with the following columns, I have been asked to concatenate visitvarname (hundreds of these combos).&lt;/P&gt;
&lt;P&gt;visit varname&lt;BR /&gt;V0, V7 AGE&lt;BR /&gt;V0, V7 SEX&lt;BR /&gt;V0, V7 RACE&lt;BR /&gt;V0, V7 HISP &lt;BR /&gt;V0, V1, V2, V3, V5, V7, V8, V9 ZLKL/ZRKL&lt;BR /&gt;V0, V1, V2, V3, V5, V7, V8, V9 ZROSFL/ZLOSFL&lt;BR /&gt;V0, V1, V2, V3, V5, V7, V8, V9 ZROSFM/ZLOSFM&lt;BR /&gt;V0, V1, V2, V3, V5, V7, V8, V9 ZROSTL/ZLOSTL&lt;BR /&gt;V00, V01, V02, V03, V04, V05, V06, V07, V08, V09, V10, V11 WOOTSR, WOOTSL&lt;BR /&gt;V00, V01, V02, V03, V04, V05, V06, V07, V08, V09, V10, V11 UPR, UPL; DOWNR, DOWNL&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm hoping I can get some help to automate the process.&lt;/P&gt;
&lt;P&gt;WANT visitvarname,&lt;/P&gt;
&lt;P&gt;V0, V7 AGE becomes V0AGE, V7AGE&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;V0, V1, V2, V3, V5, V7, V8, V9 ZLKL/ZRKL becomes &lt;BR /&gt;V0ZLKL, V1ZLKL, V2ZLKL, V3ZLKL, V5ZLKL, V7ZLKL, V8ZLKL, V9ZLKL/V0ZRKL, V1ZRKL, V2ZRKL, V3ZRKL, V5ZRKL, V7ZRKL, V8ZRKL, V9ZRKL&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;V00, V01, V02, V03, V04, V05, V06, V07, V08, V09, V10, V11 WOOTSR, WOOTSL becomes&lt;BR /&gt;V00WOOTSR, V01WOOTSR, ... V11WOOTSR/V00WOOTSL, V01WOOTSL, ... V11WOOTSL&lt;/P&gt;
&lt;P&gt;etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have imported the SAS dataset but am stumped how to do the concatenation. &lt;BR /&gt;It seems that loops and functions other than coalescec might be needed. &lt;BR /&gt;Transposing the data into long form would seem an option but then how would I get each visitvarname combo transposed back into a single row?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;visits_varname = coalescec (visits, varname);&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Appreciate any help!&lt;BR /&gt;Maggie&lt;/P&gt;</description>
    <pubDate>Tue, 16 Jan 2024 14:49:49 GMT</pubDate>
    <dc:creator>urban58</dc:creator>
    <dc:date>2024-01-16T14:49:49Z</dc:date>
    <item>
      <title>concatenate 2 character vars where there are multiple choices for each</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-2-character-vars-where-there-are-multiple-choices/m-p/911649#M359473</link>
      <description>&lt;P&gt;Hello SAS community,&lt;/P&gt;
&lt;P&gt;I successfully imported an excel sheet with the following columns, I have been asked to concatenate visitvarname (hundreds of these combos).&lt;/P&gt;
&lt;P&gt;visit varname&lt;BR /&gt;V0, V7 AGE&lt;BR /&gt;V0, V7 SEX&lt;BR /&gt;V0, V7 RACE&lt;BR /&gt;V0, V7 HISP &lt;BR /&gt;V0, V1, V2, V3, V5, V7, V8, V9 ZLKL/ZRKL&lt;BR /&gt;V0, V1, V2, V3, V5, V7, V8, V9 ZROSFL/ZLOSFL&lt;BR /&gt;V0, V1, V2, V3, V5, V7, V8, V9 ZROSFM/ZLOSFM&lt;BR /&gt;V0, V1, V2, V3, V5, V7, V8, V9 ZROSTL/ZLOSTL&lt;BR /&gt;V00, V01, V02, V03, V04, V05, V06, V07, V08, V09, V10, V11 WOOTSR, WOOTSL&lt;BR /&gt;V00, V01, V02, V03, V04, V05, V06, V07, V08, V09, V10, V11 UPR, UPL; DOWNR, DOWNL&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm hoping I can get some help to automate the process.&lt;/P&gt;
&lt;P&gt;WANT visitvarname,&lt;/P&gt;
&lt;P&gt;V0, V7 AGE becomes V0AGE, V7AGE&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;V0, V1, V2, V3, V5, V7, V8, V9 ZLKL/ZRKL becomes &lt;BR /&gt;V0ZLKL, V1ZLKL, V2ZLKL, V3ZLKL, V5ZLKL, V7ZLKL, V8ZLKL, V9ZLKL/V0ZRKL, V1ZRKL, V2ZRKL, V3ZRKL, V5ZRKL, V7ZRKL, V8ZRKL, V9ZRKL&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;V00, V01, V02, V03, V04, V05, V06, V07, V08, V09, V10, V11 WOOTSR, WOOTSL becomes&lt;BR /&gt;V00WOOTSR, V01WOOTSR, ... V11WOOTSR/V00WOOTSL, V01WOOTSL, ... V11WOOTSL&lt;/P&gt;
&lt;P&gt;etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have imported the SAS dataset but am stumped how to do the concatenation. &lt;BR /&gt;It seems that loops and functions other than coalescec might be needed. &lt;BR /&gt;Transposing the data into long form would seem an option but then how would I get each visitvarname combo transposed back into a single row?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;visits_varname = coalescec (visits, varname);&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Appreciate any help!&lt;BR /&gt;Maggie&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2024 14:49:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-2-character-vars-where-there-are-multiple-choices/m-p/911649#M359473</guid>
      <dc:creator>urban58</dc:creator>
      <dc:date>2024-01-16T14:49:49Z</dc:date>
    </item>
    <item>
      <title>Re: concatenate 2 character vars where there are multiple choices for each</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-2-character-vars-where-there-are-multiple-choices/m-p/911654#M359475</link>
      <description>&lt;P&gt;COALESCEC() and CATS() are two different operations.&amp;nbsp; They might have similar results when only one of two variables has a non-missing value.&amp;nbsp; But otherwise they are different.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you explain WHY you want to do this?&lt;/P&gt;
&lt;P&gt;Can you show a simple example input and the desired output for that input?&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2024 15:33:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-2-character-vars-where-there-are-multiple-choices/m-p/911654#M359475</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-01-16T15:33:13Z</dc:date>
    </item>
    <item>
      <title>Re: concatenate 2 character vars where there are multiple choices for each</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-2-character-vars-where-there-are-multiple-choices/m-p/911658#M359476</link>
      <description>&lt;P&gt;Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the &amp;lt;/&amp;gt; icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My first impression of this is that someone is going to take a bunch of ugly data sets imported from Excel and continue on to make even uglier sets using this to possibly rename previously created data set variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Rules are important. What is the exact rule to use for making these values? You are making us guess what the rule is for using a value like ZLKL/ZRKL much less that horrible V11 WOOTSR, WOOTSL . Guessing in general is a poor approach to programming.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this is involving other data sets perhaps those values you are appending into the names should be ADDED to the data as a new variable to describe the values in the other observations instead of placing information into variable names.&lt;/P&gt;
&lt;P&gt;Note, that for many programming tasks in SAS it would be much easier to use a list of variables named AGEV0 Agev7 because you could use a list like AgeV: to get all of the variables. Your proposed values would eliminate the chance of using shortcut lists.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2024 15:48:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-2-character-vars-where-there-are-multiple-choices/m-p/911658#M359476</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-01-16T15:48:10Z</dc:date>
    </item>
    <item>
      <title>Re: concatenate 2 character vars where there are multiple choices for each</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-2-character-vars-where-there-are-multiple-choices/m-p/911674#M359481</link>
      <description>&lt;P&gt;Hi Tom,&lt;/P&gt;
&lt;P&gt;Sorry for the poor quality of my question&lt;/P&gt;
&lt;P&gt;1. The data from the excel I shared is part of a technical document which has broken down actual SAS variable names into visits and the varname, which is a suffix - vist + suffix together make up the actual variable names in the SAS datasets. &lt;BR /&gt;I have been asked to put them back together. There are 100s of rows of these multiple visits and multiple suffixes to put back together.&lt;/P&gt;
&lt;P&gt;2. There is no simple example input, the sample data is the output from what's in the excel sheet (technical doc)&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The choices within the visit variable are V0, V1, V2, V3, etc. - number of visits vary depending on varname.&lt;/P&gt;
&lt;P&gt;V0=Visit 0&lt;BR /&gt;V1=Visit 1&lt;BR /&gt;etc.&lt;/P&gt;
&lt;P&gt;The choices within the varname or suffix can be something as simple as AGE, or more complex like ZLKL/ZRKL. For ZLKL/ZRKL, each visit choice (V0, V1, etc.) needs to be concatenated first to&amp;nbsp;ZLKL, when that's done then each visit choice (V0, V1, etc.) needs to be concatenated to&amp;nbsp;ZRKL.&lt;/P&gt;
&lt;P&gt;The delimiter in the suffix (varname column) can be a forward slash, a comma or a semicolon&lt;/P&gt;
&lt;P&gt;what I WANT is&amp;nbsp;&lt;/P&gt;
&lt;P&gt;visit&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; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; varname&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; sas_varname&lt;BR /&gt;V0, V7&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; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;AGE&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; V0AGE,V7AGE&lt;BR /&gt;V0, V1, V2, V3, V5, V7, V8, V9 ZROSFL/ZLOSFL&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; V0ZLKL,V1ZLKL,V2ZLKL,etc./V0ZRKL,V1ZRKL,V2ZRKL,etc.&lt;BR /&gt;V0, V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11 UPR, UPL; DOWNR, DOWNL V0UPR,V1UPR,V2UPR,etc./V0UPL,V1UPL,V2UPL,etc./V0DOWNR,V1DOWNR,V2DOWNR,etc./V0DOWNL,V1DOWNL,V2DOWNL,etc.&lt;/P&gt;
&lt;P&gt;Thanks for your help.&lt;BR /&gt;Maggie&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2024 16:58:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-2-character-vars-where-there-are-multiple-choices/m-p/911674#M359481</guid>
      <dc:creator>urban58</dc:creator>
      <dc:date>2024-01-16T16:58:06Z</dc:date>
    </item>
    <item>
      <title>Re: concatenate 2 character vars where there are multiple choices for each</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-2-character-vars-where-there-are-multiple-choices/m-p/911677#M359482</link>
      <description>&lt;P&gt;So it sounds like you have TWO input variables, either or which could contain a delimited list of short strings.&amp;nbsp; And your goal is to make all possible combinations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So let's assume your HAVE dataset looks like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines dsd dlm='|' truncover;
  input visit :$200. varname :$200.;
datalines;
V0, V7 | AGE
V0, V1, V2, V3, V5, V7, V8, V9 | ZROSFL/ZLOSFL V0ZLKL,V1ZLKL,V2ZLKL,/V0ZRKL,V1ZRKL,V2ZRKL
;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then just scan over both lists and concatenate them.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  length sas_varname visitpart varpart $32.;
  set have;
  do i=1 to countw(visit);
    do j=1 to countw(varname);
      visitpart=scan(visit,i);
      varpart=scan(varname,j);
      sas_varname=cats(visitpart,varpart);
      output;
    end;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1705425379451.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/92562iC6AA1E79A93F9B88/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1705425379451.png" alt="Tom_0-1705425379451.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2024 17:17:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-2-character-vars-where-there-are-multiple-choices/m-p/911677#M359482</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-01-16T17:17:17Z</dc:date>
    </item>
    <item>
      <title>Re: concatenate 2 character vars where there are multiple choices for each</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-2-character-vars-where-there-are-multiple-choices/m-p/911680#M359484</link>
      <description>&lt;P&gt;Hi Tom,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That's fantastic, thank you!&lt;/P&gt;
&lt;P&gt;I really appreciate your excellent help.&lt;/P&gt;
&lt;P&gt;Maggie&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2024 17:50:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-2-character-vars-where-there-are-multiple-choices/m-p/911680#M359484</guid>
      <dc:creator>urban58</dc:creator>
      <dc:date>2024-01-16T17:50:33Z</dc:date>
    </item>
  </channel>
</rss>

