<?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 new variable and changing wide to long format in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/creating-a-new-variable-and-changing-wide-to-long-format/m-p/714324#M220517</link>
    <description>&lt;P&gt;When I transpose each variable and merge I then have the issue that the values of the first var will repeat to fill in blanks and the same will keep happening when I add more variables. I am trying to remember how we do this, to stop filling in blanks. First obs? I am not sure. I would use something like that in my merge statement, right?&amp;nbsp; The way I have it now you can see the last ID has the same value repeating because it has 2 values for the second var. This is what others were telling me. And I believe it is okay to leave the others as missing. But I need to find out how to prevent the repetition to fill in blanks.&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;obs&lt;/TD&gt;&lt;TD&gt;med&lt;/TD&gt;&lt;TD&gt;living&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
    <pubDate>Tue, 26 Jan 2021 17:10:22 GMT</pubDate>
    <dc:creator>Mscarboncopy</dc:creator>
    <dc:date>2021-01-26T17:10:22Z</dc:date>
    <item>
      <title>creating a new variable and changing wide to long format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-a-new-variable-and-changing-wide-to-long-format/m-p/714026#M220373</link>
      <description>&lt;P&gt;Hi I am trying to find out what is the best way to create a variable that I need and change the file format at the same time. My file looks like this (0 is not selected, 1 is selected). I need to create a variable called med that would have values 0 to 8 (depending on what was answered for med_1 to med_8). My issue is that if I use an array it will overwrite, as any ID (obs) can have multiple combinations of selected options (they can select all options or none and any combination in between). I could add all the possible combinations, however, my data file has other variables with 1-50 answer options&amp;nbsp; that can be all selected, and I was hoping to do the same for those. I will not need the non selected (0). My goal is to have a final long data file that only contains the observations that selected at least one of the options. I have looked at wide to long articles and answers here, but I can't seem to adapt the information to what I need. Thank you.&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;OBS&lt;/TD&gt;&lt;TD&gt;med___1&lt;/TD&gt;&lt;TD&gt;med___2&lt;/TD&gt;&lt;TD&gt;med___3&lt;/TD&gt;&lt;TD&gt;med___4&lt;/TD&gt;&lt;TD&gt;med___5&lt;/TD&gt;&lt;TD&gt;med___6&lt;/TD&gt;&lt;TD&gt;med___7&lt;/TD&gt;&lt;TD&gt;med___8&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Mon, 25 Jan 2021 19:18:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-a-new-variable-and-changing-wide-to-long-format/m-p/714026#M220373</guid>
      <dc:creator>Mscarboncopy</dc:creator>
      <dc:date>2021-01-25T19:18:42Z</dc:date>
    </item>
    <item>
      <title>Re: creating a new variable and changing wide to long format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-a-new-variable-and-changing-wide-to-long-format/m-p/714029#M220375</link>
      <description>&lt;P&gt;So what does your desired long data look like given this sample?&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jan 2021 19:26:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-a-new-variable-and-changing-wide-to-long-format/m-p/714029#M220375</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-01-25T19:26:26Z</dc:date>
    </item>
    <item>
      <title>Re: creating a new variable and changing wide to long format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-a-new-variable-and-changing-wide-to-long-format/m-p/714044#M220380</link>
      <description>&lt;P&gt;Since you mention that you have a lot of other variables it would be a good idea to share how you expect the data to look including some of those others.&lt;/P&gt;
&lt;P&gt;It may help to provide a worked example using a smaller set of values, say med_1 to med_4 and similar for at least one other variable if it is also a multiple response value like these Med values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jan 2021 20:07:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-a-new-variable-and-changing-wide-to-long-format/m-p/714044#M220380</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-01-25T20:07:50Z</dc:date>
    </item>
    <item>
      <title>Re: creating a new variable and changing wide to long format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-a-new-variable-and-changing-wide-to-long-format/m-p/714049#M220383</link>
      <description>&lt;P&gt;5 is not&amp;nbsp; there because it only had 0's nothing selected. it would look like this.&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;OBS&lt;/TD&gt;&lt;TD&gt;Med&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Mon, 25 Jan 2021 20:24:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-a-new-variable-and-changing-wide-to-long-format/m-p/714049#M220383</guid>
      <dc:creator>Mscarboncopy</dc:creator>
      <dc:date>2021-01-25T20:24:27Z</dc:date>
    </item>
    <item>
      <title>Re: creating a new variable and changing wide to long format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-a-new-variable-and-changing-wide-to-long-format/m-p/714050#M220384</link>
      <description>&lt;P&gt;Yes, the others are also select not select, exactly like the med vars here. Thank you.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jan 2021 20:25:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-a-new-variable-and-changing-wide-to-long-format/m-p/714050#M220384</guid>
      <dc:creator>Mscarboncopy</dc:creator>
      <dc:date>2021-01-25T20:25:31Z</dc:date>
    </item>
    <item>
      <title>Re: creating a new variable and changing wide to long format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-a-new-variable-and-changing-wide-to-long-format/m-p/714058#M220387</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/210474"&gt;@Mscarboncopy&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Yes, the others are also select not select, exactly like the med vars here. Thank you.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You need to show what the output involving these other variables would be. It seems pretty obvious that there should be another another variable but how to generate it is not obvious because what if the Obs=1 has 3 values for the other variable? You currently have exactly 1 value for Med but what happens with the other variable involved? This can get to be a very complex issue depending on what you think you want.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jan 2021 20:35:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-a-new-variable-and-changing-wide-to-long-format/m-p/714058#M220387</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-01-25T20:35:17Z</dc:date>
    </item>
    <item>
      <title>Re: creating a new variable and changing wide to long format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-a-new-variable-and-changing-wide-to-long-format/m-p/714067#M220391</link>
      <description>&lt;P&gt;Oh, I see what you mean. I apologize.&lt;/P&gt;&lt;P&gt;So yes, it would have an issue right? Especially when I am adding variables that have 50+ options. So I added a var Living with 1-8 values just like Med. 0 for not selected, 1-8 to the selected ones.&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;OBS&lt;/TD&gt;&lt;TD&gt;Med&lt;/TD&gt;&lt;TD&gt;Living&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Mon, 25 Jan 2021 20:51:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-a-new-variable-and-changing-wide-to-long-format/m-p/714067#M220391</guid>
      <dc:creator>Mscarboncopy</dc:creator>
      <dc:date>2021-01-25T20:51:28Z</dc:date>
    </item>
    <item>
      <title>Re: creating a new variable and changing wide to long format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-a-new-variable-and-changing-wide-to-long-format/m-p/714228#M220478</link>
      <description>&lt;P&gt;Also I can output the other variables that involve more than 50 selection options as their own file. This would allow me to have a smaller (separate) file with the variables that are like med and living(shown here). But I still need to know how to create the new vars, changing the format and how to handle the missing shown. Thank you.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jan 2021 12:18:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-a-new-variable-and-changing-wide-to-long-format/m-p/714228#M220478</guid>
      <dc:creator>Mscarboncopy</dc:creator>
      <dc:date>2021-01-26T12:18:35Z</dc:date>
    </item>
    <item>
      <title>Re: creating a new variable and changing wide to long format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-a-new-variable-and-changing-wide-to-long-format/m-p/714232#M220480</link>
      <description>&lt;P&gt;Transpose first, and then transform the result:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input OBS med___1 med___2 med___3 med___4 med___5 med___6 med___7 med___8;
datalines;
1 0 0 0 0 0 0 0 1
2 1 0 1 0 0 0 0 0
3 1 0 0 0 0 0 0 0
4 1 1 1 0 0 0 0 0
5 0 0 0 0 0 0 0 0
6 1 1 1 1 1 0 0 0
;

proc transpose
  data=have
  out=long (
    where=(col1 ne 0)
  )
;
by obs;
var med:;
run;

data want;
set long;
med = scan(_name_,-1,"_");
drop _name_ col1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Jan 2021 12:56:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-a-new-variable-and-changing-wide-to-long-format/m-p/714232#M220480</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-01-26T12:56:22Z</dc:date>
    </item>
    <item>
      <title>Re: creating a new variable and changing wide to long format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-a-new-variable-and-changing-wide-to-long-format/m-p/714314#M220510</link>
      <description>&lt;P&gt;This is it! Thank you so much.&lt;/P&gt;&lt;P&gt;Questions:&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. Can I add other variables to this?&amp;nbsp; If I am adding other vars (A B C) would this be correct below.&lt;/P&gt;&lt;P&gt;2. what is the vat col2? My output is showing col2 and they are all missing except one obs has a 1.&lt;/P&gt;&lt;LI-CODE lang="sas"&gt;proc transpose
  data=have
  out=long (
    where=(col1 ne 0)
  )
;
by obs;
var med: A: B: C:;
run;

data want;
set long;
med = scan(_name_,-1,"_");
A= scan(_name_,-1,"_");
B = scan(_name_,-1,"_");
C= scan(_name_,-1,"_");
drop _name_ col1;
run;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jan 2021 16:41:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-a-new-variable-and-changing-wide-to-long-format/m-p/714314#M220510</guid>
      <dc:creator>Mscarboncopy</dc:creator>
      <dc:date>2021-01-26T16:41:19Z</dc:date>
    </item>
    <item>
      <title>Re: creating a new variable and changing wide to long format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-a-new-variable-and-changing-wide-to-long-format/m-p/714319#M220514</link>
      <description>&lt;P&gt;I see this does not work if I want to add more variables. It overwrites. This is the issue brought up before. So my option would be maybe proc transpose each variable and then merge the files ?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jan 2021 16:49:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-a-new-variable-and-changing-wide-to-long-format/m-p/714319#M220514</guid>
      <dc:creator>Mscarboncopy</dc:creator>
      <dc:date>2021-01-26T16:49:08Z</dc:date>
    </item>
    <item>
      <title>Re: creating a new variable and changing wide to long format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-a-new-variable-and-changing-wide-to-long-format/m-p/714324#M220517</link>
      <description>&lt;P&gt;When I transpose each variable and merge I then have the issue that the values of the first var will repeat to fill in blanks and the same will keep happening when I add more variables. I am trying to remember how we do this, to stop filling in blanks. First obs? I am not sure. I would use something like that in my merge statement, right?&amp;nbsp; The way I have it now you can see the last ID has the same value repeating because it has 2 values for the second var. This is what others were telling me. And I believe it is okay to leave the others as missing. But I need to find out how to prevent the repetition to fill in blanks.&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;obs&lt;/TD&gt;&lt;TD&gt;med&lt;/TD&gt;&lt;TD&gt;living&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Tue, 26 Jan 2021 17:10:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-a-new-variable-and-changing-wide-to-long-format/m-p/714324#M220517</guid>
      <dc:creator>Mscarboncopy</dc:creator>
      <dc:date>2021-01-26T17:10:22Z</dc:date>
    </item>
    <item>
      <title>Re: creating a new variable and changing wide to long format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-a-new-variable-and-changing-wide-to-long-format/m-p/714331#M220523</link>
      <description>&lt;P&gt;To avoid the automatic RETAIN (the feature that makes one to many merges work right) you can use CALL MISSING().&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   merge one two three;
   by id;
   output;
   call missing(of _all_);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Jan 2021 17:39:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-a-new-variable-and-changing-wide-to-long-format/m-p/714331#M220523</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-01-26T17:39:30Z</dc:date>
    </item>
    <item>
      <title>Re: creating a new variable and changing wide to long format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-a-new-variable-and-changing-wide-to-long-format/m-p/714337#M220525</link>
      <description>&lt;P&gt;That is perfect. Thank you Tom. Can I just ignore the var COL2 in my output? I am planning on dropping it, but just wanted to make sure I do not need to use it to check for issues.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jan 2021 17:52:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-a-new-variable-and-changing-wide-to-long-format/m-p/714337#M220525</guid>
      <dc:creator>Mscarboncopy</dc:creator>
      <dc:date>2021-01-26T17:52:46Z</dc:date>
    </item>
    <item>
      <title>Re: creating a new variable and changing wide to long format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-a-new-variable-and-changing-wide-to-long-format/m-p/714494#M220591</link>
      <description>&lt;P&gt;When you get a COL2 variable, this means that the BY variable is not unique, there are two observations for at least one OBS in your original dataset.&lt;/P&gt;
&lt;P&gt;For a transpose like this to work consistently, you need to make sure first that your BY variable is unique.&lt;/P&gt;
&lt;P&gt;Then, you do a double transpose with some little preparation in between:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id $ med_1 med_2 liv_1 liv_2;
datalines;
A 0 1 1 0
B 1 1 0 1
C 1 0 0 1
D 1 1 1 1
;

proc transpose
  data=have
  out=long1 (where=(col1 ne 0))
;
by id;
var med: liv:;
run;

data long2;
set long1;
seq = input(scan(_name_,2,"_"),best.);
_name_ = scan(_name_,1,"_");
run;

proc sort data=long2;
by id seq;
run;

proc transpose
  data=long2
  out=want (drop=seq _name_)
;
by id seq;
var seq;
id _name_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jan 2021 08:15:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-a-new-variable-and-changing-wide-to-long-format/m-p/714494#M220591</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-01-27T08:15:08Z</dc:date>
    </item>
    <item>
      <title>Re: creating a new variable and changing wide to long format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-a-new-variable-and-changing-wide-to-long-format/m-p/714545#M220607</link>
      <description>&lt;P&gt;Thank you so much ! So the "repeated by values" is not because the data is being stacked (long) and I would have more than one observation for each OBS? It is coming from the original? If so, I would have to find out which one it is, because that would indicate a mistake in my raw data. We are not supposed to have repeated obs for each OBS in the original file. I see only one observation with a value of 1 in column 2 which would mean I only have one repeated Id maybe. Could I use COL2 to find out this quickly? If so, how? Thanks again.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jan 2021 12:50:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-a-new-variable-and-changing-wide-to-long-format/m-p/714545#M220607</guid>
      <dc:creator>Mscarboncopy</dc:creator>
      <dc:date>2021-01-27T12:50:41Z</dc:date>
    </item>
    <item>
      <title>Re: creating a new variable and changing wide to long format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-a-new-variable-and-changing-wide-to-long-format/m-p/714547#M220609</link>
      <description>&lt;P&gt;Just take the OBS value from the observation where COL2 is not missing, and use that to search in your raw data. Checking for duplicates is one part of my Maxim 3 (Know Your Data).&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jan 2021 12:54:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-a-new-variable-and-changing-wide-to-long-format/m-p/714547#M220609</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-01-27T12:54:45Z</dc:date>
    </item>
    <item>
      <title>Re: creating a new variable and changing wide to long format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-a-new-variable-and-changing-wide-to-long-format/m-p/714591#M220626</link>
      <description>&lt;P&gt;yes, of course. Sometimes I am trying to do things differently and forget the basics. I did find the one id that was indeed incorrectly entered. Col2 is then perfect for me to check for these issues. I really appreciate your help. I have another question. How do I transpose string and date variables? I tried to use the code provided but it did not work. I will give an example because it will add complexity.&lt;/P&gt;&lt;P&gt;I am using the transpose for all the numeric variables. Some of them, not all, have a corresponding string variable. So for example in the example I gave,&amp;nbsp; if med 1 is selected a string one will appear. If med 2 is selected a string 2 will appear and so on. So I would need to create a common var String (instead of string 1, string 2 and so on) that would assign each string to each key selected in the Med var.&amp;nbsp; I would do the same with dates variables that are sometimes asked for the numeric variables the same way I would do the strings. Thank you again.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jan 2021 14:45:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-a-new-variable-and-changing-wide-to-long-format/m-p/714591#M220626</guid>
      <dc:creator>Mscarboncopy</dc:creator>
      <dc:date>2021-01-27T14:45:19Z</dc:date>
    </item>
    <item>
      <title>Re: creating a new variable and changing wide to long format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-a-new-variable-and-changing-wide-to-long-format/m-p/714604#M220630</link>
      <description>&lt;P&gt;The double transpose is only good for variables with similar attributes; for mixed types/attributes (e.g.character, "normal" numeric and numeric/dates), it's better to transpose the variable groups separately and merge back.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jan 2021 15:05:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-a-new-variable-and-changing-wide-to-long-format/m-p/714604#M220630</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-01-27T15:05:42Z</dc:date>
    </item>
    <item>
      <title>Re: creating a new variable and changing wide to long format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-a-new-variable-and-changing-wide-to-long-format/m-p/714621#M220637</link>
      <description>&lt;P&gt;Understood. I am planning on doing that. But I am not sure if I need to change the transpose, when I use it for string and dates it does not work. I am wondering if I am doing something wrong.I am using the code provided here and adding the string variable names where you see the&amp;nbsp; numeric variable names. there is probably a change needed for variables that are not numeric?&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jan 2021 15:47:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-a-new-variable-and-changing-wide-to-long-format/m-p/714621#M220637</guid>
      <dc:creator>Mscarboncopy</dc:creator>
      <dc:date>2021-01-27T15:47:23Z</dc:date>
    </item>
  </channel>
</rss>

