<?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: Converting data from wide to long in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Converting-data-from-wide-to-long/m-p/727172#M226110</link>
    <description>&lt;P&gt;Thank you so much for your response. I have attached a few lines of the data. I hope this makes it clearer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;</description>
    <pubDate>Wed, 17 Mar 2021 16:50:05 GMT</pubDate>
    <dc:creator>UcheOkoro</dc:creator>
    <dc:date>2021-03-17T16:50:05Z</dc:date>
    <item>
      <title>Converting data from wide to long</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-data-from-wide-to-long/m-p/726890#M225944</link>
      <description>&lt;P&gt;Please, I need help converting data from wide to long. I have a data set which has data in wide form. It has drug_class1 - drug_class25 , drug_name1-drug_name25 and&amp;nbsp; the&amp;nbsp; drug indication starts from&amp;nbsp; drug_indication1_21-drug_indication25_40..&lt;/P&gt;
&lt;P&gt;I would like to transpose the data to look like this&amp;nbsp;&lt;/P&gt;
&lt;P&gt;encounter_id&amp;nbsp; drug_class drug_name&amp;nbsp; indication21&amp;nbsp; .................................indication40.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My main problem is how to transpose the drug_indication. I tried the following code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=Data_new out=long_indication_meds prefix=indication_meds;
   by encounterid;
   var indication_meds1___21 - indication_meds25___40;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but got the following error message&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT size="4"&gt;ERROR: Either roots don't match or start suffix after end suffix&lt;/FONT&gt;.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance&lt;/P&gt;</description>
      <pubDate>Tue, 16 Mar 2021 19:50:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-data-from-wide-to-long/m-p/726890#M225944</guid>
      <dc:creator>UcheOkoro</dc:creator>
      <dc:date>2021-03-16T19:50:12Z</dc:date>
    </item>
    <item>
      <title>Re: Converting data from wide to long</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-data-from-wide-to-long/m-p/726896#M225948</link>
      <description>&lt;P&gt;When you use variable list like Var_1 - Var15 SAS expects there to be 15 variables, sequentially numbered and the "root" which would be "Var_" to be the same.&lt;/P&gt;
&lt;P&gt;Your use drug_indication1_21-drug_indication25_40 does not have a "root" that is the same. From that I have no idea if the "next" variable name after drug_indication1_21 would be drug_indication2_21,drug_indication1_22, drug_indication2_22 or what. Neither does SAS.&lt;/P&gt;
&lt;P&gt;So either type out all of the names or use one of the other forms of lists.&lt;/P&gt;
&lt;P&gt;If all of the drug_indication variables are adjacent columns (run proc contents and see if the variable # in the output is sequential for those variables). If so you could use the two dash list:&amp;nbsp; drug_indication1_21 -- drug_indication25_40 , which would use the variables in column order.&lt;/P&gt;
&lt;P&gt;If they are not sequential then &lt;STRONG&gt;possibly&lt;/STRONG&gt; you could use the list form of : drug_indication:&amp;nbsp; the : after the part of the name says to use ALL of the variables whose names start with the common characters. There could however be a an issue that the order variable names are added to the list is not the expected order.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your code shows :prefix=indication_meds&lt;/P&gt;
&lt;P&gt;This means the output variables would be named&amp;nbsp;indication_meds1,&amp;nbsp;indication_meds2, ...&amp;nbsp;indication_medsXX&lt;/P&gt;
&lt;P&gt;not the stated Indication21&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However it looks more like what you want to do is RENAME variables. Which could be done in Proc datasets or&amp;nbsp; a data step (inefficient in cpu time, about the same in coding time)&lt;/P&gt;
&lt;PRE&gt;proc datasets library=work;
   modify data_new;
      rename 
         drug_indication1_21= indication21
         ...(you provide each pair)
         drug_indication25_40= indication40
      ;
   run;
quit;&lt;/PRE&gt;
&lt;P&gt;If not Provide some example data, with only 3 drug class and names with maybe 5 or 6 "drug_indication" variables. Then show what you expect to see for output.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Mar 2021 20:14:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-data-from-wide-to-long/m-p/726896#M225948</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-03-16T20:14:03Z</dc:date>
    </item>
    <item>
      <title>Re: Converting data from wide to long</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-data-from-wide-to-long/m-p/726930#M225971</link>
      <description>&lt;P&gt;Thank you so much for your response. The indication_21.......indication_40 was an error. What I had in mind was drug_indication21.........drug_indication_40.&lt;/P&gt;
&lt;P&gt;I did a proc contents and noticed that the v&lt;SPAN&gt;ariable # in the output is not sequential for those variables because there is another set of variables other_indication1.......other_indications25 which has character observations( eg. "History of allergy to iodine ".)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Renaming the variable is going to be a gruely task because they are over 500.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Sample data:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;What I have is the following&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;id&amp;nbsp; drug_class1&amp;nbsp; drug_name1&amp;nbsp; drug_indication1_21 ........&amp;nbsp;drug_indication1_40&amp;nbsp; &amp;nbsp;........drug_class25&amp;nbsp; &amp;nbsp; &amp;nbsp;drug_name25&amp;nbsp; drug_indication25_21 ...... drug_indication25_40&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; NSAID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Aspirin&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&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; 0&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;Antihistamine&amp;nbsp; &amp;nbsp; &amp;nbsp;Cetirizine&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&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;1&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Opioid&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;hydrocodone&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&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; 1&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; NSAID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Aspirin&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&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;0&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;What I want to see is&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;What I expect to see is the following&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;s/n&amp;nbsp; &amp;nbsp; &amp;nbsp; id&amp;nbsp; drug_class&amp;nbsp; &amp;nbsp; &amp;nbsp; drug_name&amp;nbsp; &amp;nbsp; &amp;nbsp;drug_indication21................................drug_indication40&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;SPAN&gt;NSAID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;Aspirin&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 ......................................... ...................0&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;2&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; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.............................................................&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&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; &amp;nbsp; &amp;nbsp;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .......................................................................&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&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; &amp;nbsp;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;..................................................................&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&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; &amp;nbsp; &amp;nbsp;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ...................................................................&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&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; &amp;nbsp;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ..................................................................&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; 25&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp;Antihistamine&amp;nbsp; &amp;nbsp; &amp;nbsp;Cetirizine&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0................................................................ ..1&amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 26&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;SPAN&gt;Opioid&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; hydrocodone&amp;nbsp; &amp;nbsp; 1 ............................................ .....................0&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&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; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.............................................................&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&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;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .......................................................................&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&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;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;..................................................................&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&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;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ...................................................................&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&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;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ..................................................................&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; 50&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; NSAID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Aspirin&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1......................................................................0&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I hope this is clear?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thank you.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;&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;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Mar 2021 22:41:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-data-from-wide-to-long/m-p/726930#M225971</guid>
      <dc:creator>UcheOkoro</dc:creator>
      <dc:date>2021-03-16T22:41:52Z</dc:date>
    </item>
    <item>
      <title>Re: Converting data from wide to long</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-data-from-wide-to-long/m-p/726942#M225978</link>
      <description>&lt;P&gt;If your source data was a text file and you copy something like the first 5 lines and paste them into a text box (&lt;STRONG&gt;critical!&lt;/STRONG&gt;) we may be able to show you how to read that file directly to create that data structure.&lt;/P&gt;
&lt;P&gt;If your source data was in a different format tell us what type file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Consider this example, which only has 3 sets of values consisting of two "words" and 5 numeric values:&lt;/P&gt;
&lt;PRE&gt;data example;
   infile datalines dlm=',' dsd;
   informat worda wordb $10. value1-value5  best.;
   input id @;
   do i=1 to 3;
      input worda wordb value1-value5 @;
      output;
   end;
   input;
   drop i;
datalines;
1,abc,pdq,1,0,0,1,1,zz,top,0,0,0,0,1,john,doe,1,1,1,1,0
1,aaa,ggq,1,0,0,1,1,z3,bgt,0,0,0,0,1,mary,pit,1,1,1,1,0
;

&lt;/PRE&gt;
&lt;P&gt;The infile statement would point to a text file but here it shows some options if the original data were comma separated (CSV). The DLM option tells SAS to expect a comma between values. The DSD option means that if there are two successive delimiters to treat that variable as missing.&lt;/P&gt;
&lt;P&gt;The Informat describes how to read each variable, worda and wordb as character, and then 5 numeric variables as numbers (not actually needed as a default but to make basis for when more complicated things come up). The ID could be numeric or character.&lt;/P&gt;
&lt;P&gt;The first input reads just the ID value. The @ symbol at the end of an input means "hold the reading pointer on the current record where it is", which in this case would be right after the ID.&lt;/P&gt;
&lt;P&gt;Since we KNOW we have 3 sets of variables we can use a loop to specify that number of times to read, still using the @ to hold the pointer. The OUTPUT statement says to write the current data to the output data set.&lt;/P&gt;
&lt;P&gt;After the Loop we need an explicit Input to advance to the next row of data.&lt;/P&gt;
&lt;P&gt;The I value isn't needed, unless you want a line or group indicator for some reason. If so pick a name that means more than the "i" and don't use the Drop statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If not all 3 groups are present you will get some blank lines currently. That could be fixed by using "If not missing(worda) then output;" instead of the simple output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another option might be to EXPORT your existing data to CSV and write a program similar to above to read it.&lt;/P&gt;
&lt;P&gt;You did mention other variables. Where they appear is going to make a difference but as long as the pattern is regular it is quite doable, just somewhat cumbersome code.&lt;/P&gt;
&lt;P&gt;For example if you had indication1 otherindication1 indication2 otherindication2 etc as the column order then the Input statement would just list those.&lt;/P&gt;
&lt;P&gt;The headaches come if the "other" are mixed in after the the drug type and name group of values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Mar 2021 23:44:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-data-from-wide-to-long/m-p/726942#M225978</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-03-16T23:44:51Z</dc:date>
    </item>
    <item>
      <title>Re: Converting data from wide to long</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-data-from-wide-to-long/m-p/727172#M226110</link>
      <description>&lt;P&gt;Thank you so much for your response. I have attached a few lines of the data. I hope this makes it clearer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Mar 2021 16:50:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-data-from-wide-to-long/m-p/727172#M226110</guid>
      <dc:creator>UcheOkoro</dc:creator>
      <dc:date>2021-03-17T16:50:05Z</dc:date>
    </item>
    <item>
      <title>Re: Converting data from wide to long</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-data-from-wide-to-long/m-p/727484#M226277</link>
      <description>&lt;P&gt;Renaming the variables worked for me. Thank you so much&lt;/P&gt;</description>
      <pubDate>Thu, 18 Mar 2021 17:23:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-data-from-wide-to-long/m-p/727484#M226277</guid>
      <dc:creator>UcheOkoro</dc:creator>
      <dc:date>2021-03-18T17:23:03Z</dc:date>
    </item>
  </channel>
</rss>

