<?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: Transposing Data with Repeated Values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Transposing-Data-with-Repeated-Values/m-p/695501#M212240</link>
    <description>&lt;P&gt;Hint: Show some data with the repeats.&lt;/P&gt;
&lt;P&gt;Then show how the output should look.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It may be that you want an additional variable or two on the by statement, perhaps Year.&lt;/P&gt;</description>
    <pubDate>Fri, 30 Oct 2020 15:05:32 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2020-10-30T15:05:32Z</dc:date>
    <item>
      <title>Transposing Data with Repeated Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-Data-with-Repeated-Values/m-p/695498#M212239</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance for your help. I am working with SAS 9.4 version, and need help with transposing my data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The data original format is as follows:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="548"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="64"&gt;value&lt;/TD&gt;
&lt;TD width="64"&gt;admin&lt;/TD&gt;
&lt;TD width="154"&gt;Epi_value&lt;/TD&gt;
&lt;TD width="202"&gt;Epi_metric&lt;/TD&gt;
&lt;TD width="64"&gt;Year&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;44&lt;/TD&gt;
&lt;TD&gt;Afghanistan&lt;/TD&gt;
&lt;TD&gt;1500&lt;/TD&gt;
&lt;TD&gt;epi_HIV Incidence&lt;/TD&gt;
&lt;TD&gt;2019&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;44&lt;/TD&gt;
&lt;TD&gt;Afghanistan&lt;/TD&gt;
&lt;TD&gt;50&lt;/TD&gt;
&lt;TD&gt;epi_infections Five year percent change&lt;/TD&gt;
&lt;TD&gt;2019&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;44&lt;/TD&gt;
&lt;TD&gt;Afghanistan&lt;/TD&gt;
&lt;TD&gt;36.4&lt;/TD&gt;
&lt;TD&gt;epi_infections compare 2015 percent change&lt;/TD&gt;
&lt;TD&gt;2019&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;44&lt;/TD&gt;
&lt;TD&gt;Afghanistan&lt;/TD&gt;
&lt;TD&gt;36&lt;/TD&gt;
&lt;TD&gt;epi_ART known treatment&lt;/TD&gt;
&lt;TD&gt;2019&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;44&lt;/TD&gt;
&lt;TD colspan="2"&gt;Afghanistan&lt;/TD&gt;
&lt;TD&gt;epi_ART change_art_2015&lt;/TD&gt;
&lt;TD&gt;2019&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to transpose my data so then the "Epi_metric" variables are their own columns, with the corresponding "Epi_value" values, per country and year. This source only contains data for the Year 2019, and the "Epi_metric" variable repeats for each country.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd appreciate any help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Current Code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
* Research Objective: Exploratory data analysis for HIV Lab;

*______________________________________________________________;

*Import datasets and Merge;

Data HIV_Data; *HIV Policy Lab, including HIV incidence metrics;
  	INFILE "C:\Users\Briana.Thrift.ctr\Downloads\epi_data_all_values.csv" dsd firstobs=2 truncover ;
	LENGTH admin $54 epi_metric $54;
  	INPUT value	admin$	epi_value	epi_metric$	Year
;

	Rename admin=Country_Name;
Run;

Proc contents data=HIV_Data;
Run;

Proc Print data=HIV_Data (obs=2);
Run;

*Transpose the Data;

Proc sort data=HIV_Data;
	by Country_Name;
Run;

Proc Transpose data=HIV_Data out=wide_EpiMetric prefix=epi_metric;
   by Country_Name;
   id epi_metric;
   var epi_value;
Run;

Proc print data=wide_EpiMetric (obs=2);
Run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Current SAS Error Message:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
10559  Proc Transpose data=HIV_Data out=wide_EpiMetric prefix=epi_metric;
10560     by Country_Name;
10561     id epi_metric;
10562     var epi_value;
10563  Run;

ERROR: The ID value "epi_metricepi_HIV_patients_on_AR" occurs twice in the same BY group.
ERROR: The ID value "epi_metricepi_HIV_patients_on_AR" occurs twice in the same BY group.
ERROR: The ID value "epi_metricepi_HIV_patients_on_AR" occurs twice in the same BY group.
ERROR: The ID value "epi_metricepi_HIV_patients_on_AR" occurs twice in the same BY group.
NOTE: The above message was for the following BY group:
      Country_Name=Afghanistan
ERROR: The ID value "epi_metricepi_HIV_patients_on_AR" occurs twice in the same BY group.
ERROR: The ID value "epi_metricepi_HIV_patients_on_AR" occurs twice in the same BY group.
ERROR: The ID value "epi_metricepi_HIV_patients_on_AR" occurs twice in the same BY group.
ERROR: The ID value "epi_metricepi_HIV_patients_on_AR" occurs twice in the same BY group.
NOTE: The above message was for the following BY group:
      Country_Name=Albania
ERROR: The ID value "epi_metricepi_HIV_patients_on_AR" occurs twice in the same BY group.
ERROR: The ID value "epi_metricepi_HIV_patients_on_AR" occurs twice in the same BY group.
ERROR: The ID value "epi_metricepi_HIV_patients_on_AR" occurs twice in the same BY group.
ERROR: The ID value "epi_metricepi_HIV_patients_on_AR" occurs twice in the same BY group.
NOTE: The above message was for the following BY group:
      Country_Name=Algeria
ERROR: The ID value "epi_metricepi_HIV_patients_on_AR" occurs twice in the same BY group.
ERROR: The ID value "epi_metricepi_HIV_patients_on_AR" occurs twice in the same BY group.
ERROR: The ID value "epi_metricepi_HIV_patients_on_AR" occurs twice in the same BY group.
ERROR: The ID value "epi_metricepi_HIV_patients_on_AR" occurs twice in the same BY group.
NOTE: The above message was for the following BY group:
      Country_Name=Angola
ERROR: The ID value "epi_metricepi_HIV_patients_on_AR" occurs twice in the same BY group.
ERROR: The ID value "epi_metricepi_HIV_patients_on_AR" occurs twice in the same BY group.
ERROR: The ID value "epi_metricepi_HIV_patients_on_AR" occurs twice in the same BY group.
ERROR: The ID value "epi_metricepi_HIV_patients_on_AR" occurs twice in the same BY group.
NOTE: The above message was for the following BY group:
      Country_Name=Argentina
ERROR: The ID value "epi_metricepi_HIV_patients_on_AR" occurs twice in the same BY group.
ERROR: The ID value "epi_metricepi_HIV_patients_on_AR" occurs twice in the same BY group.
ERROR: The ID value "epi_metricepi_HIV_patients_on_AR" occurs twice in the same BY group.
ERROR: The ID value "epi_metricepi_HIV_patients_on_AR" occurs twice in the same BY group.
NOTE: The above message was for the following BY group:
      Country_Name=Armenia
ERROR: The ID value "epi_metricepi_HIV_patients_on_AR" occurs twice in the same BY group.
ERROR: The ID value "epi_metricepi_HIV_patients_on_AR" occurs twice in the same BY group.
ERROR: The ID value "epi_metricepi_HIV_patients_on_AR" occurs twice in the same BY group.
ERROR: The ID value "epi_metricepi_HIV_patients_on_AR" occurs twice in the same BY group.
NOTE: The above message was for the following BY group:
      Country_Name=Australia
ERROR: The ID value "epi_metricepi_HIV_patients_on_AR" occurs twice in the same BY group.
ERROR: The ID value "epi_metricepi_HIV_patients_on_AR" occurs twice in the same BY group.
ERROR: The ID value "epi_metricepi_HIV_patients_on_AR" occurs twice in the same BY group.
ERROR: The ID value "epi_metricepi_HIV_patients_on_AR" occurs twice in the same BY group.
NOTE: The above message was for the following BY group:
      Country_Name=Austria
ERROR: The ID value "epi_metricepi_HIV_patients_on_AR" occurs twice in the same BY group.
ERROR: The ID value "epi_metricepi_HIV_patients_on_AR" occurs twice in the same BY group.
ERROR: The ID value "epi_metricepi_HIV_patients_on_AR" occurs twice in the same BY group.
ERROR: The ID value "epi_metricepi_HIV_patients_on_AR" occurs twice in the same BY group.
NOTE: The above message was for the following BY group:
      Country_Name=Azerbaijan
ERROR: The ID value "epi_metricepi_HIV_patients_on_AR" occurs twice in the same BY group.
ERROR: The ID value "epi_metricepi_HIV_patients_on_AR" occurs twice in the same BY group.
ERROR: Too many bad BY groups.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: There were 116 observations read from the data set WORK.HIV_DATA.
WARNING: The data set WORK.WIDE_EPIMETRIC may be incomplete.  When this step was stopped there were 0 observations and 0 variables.
WARNING: Data set WORK.WIDE_EPIMETRIC was not replaced because this step was stopped.
NOTE: PROCEDURE TRANSPOSE used (Total process time):
      real time           0.02 seconds
      cpu time            0.01 seconds

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thank you!&lt;/P&gt;
&lt;P&gt;Briana Thrift&lt;/P&gt;</description>
      <pubDate>Fri, 30 Oct 2020 14:49:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-Data-with-Repeated-Values/m-p/695498#M212239</guid>
      <dc:creator>brianathrift</dc:creator>
      <dc:date>2020-10-30T14:49:40Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing Data with Repeated Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-Data-with-Repeated-Values/m-p/695501#M212240</link>
      <description>&lt;P&gt;Hint: Show some data with the repeats.&lt;/P&gt;
&lt;P&gt;Then show how the output should look.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It may be that you want an additional variable or two on the by statement, perhaps Year.&lt;/P&gt;</description>
      <pubDate>Fri, 30 Oct 2020 15:05:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-Data-with-Repeated-Values/m-p/695501#M212240</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-10-30T15:05:32Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing Data with Repeated Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-Data-with-Repeated-Values/m-p/695502#M212241</link>
      <description>&lt;P&gt;I can't replicate the error with this small example data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please provide a larger portion of your data that illustrates the error. Do not provide data as a screen capture. Provide the data following &lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;these instructions&lt;/A&gt;. Thank you.&lt;/P&gt;</description>
      <pubDate>Fri, 30 Oct 2020 14:58:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-Data-with-Repeated-Values/m-p/695502#M212241</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-10-30T14:58:21Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing Data with Repeated Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-Data-with-Repeated-Values/m-p/695513#M212247</link>
      <description>&lt;P&gt;I add that (depending on what you are trying to do), you might be MUCH better off leaving this data set long instead of wide. There are many operations in SAS that can be programmed and executed easier with a long data set instead of a wide data set (see &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Maxims-of-Maximally-Efficient-SAS-Programmers/ta-p/352068" target="_self"&gt;Maxim 19&lt;/A&gt;).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Creating variables with these long names such as&amp;nbsp;&lt;SPAN&gt;epi_infections_Five_year_percent_change and so on will be a nightmare to program.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;BR /&gt;So what are you going to do with this data?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Oct 2020 15:30:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-Data-with-Repeated-Values/m-p/695513#M212247</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-10-30T15:30:18Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing Data with Repeated Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-Data-with-Repeated-Values/m-p/695520#M212250</link>
      <description>&lt;P&gt;SAS has a 32 character limit for variable names, so the contents of the ID variable have to be unique in the first 32 characters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Based on experience, there is a more than fair chance that you are better off leaving the data in long format.&lt;/P&gt;</description>
      <pubDate>Fri, 30 Oct 2020 16:10:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-Data-with-Repeated-Values/m-p/695520#M212250</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-10-30T16:10:52Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing Data with Repeated Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-Data-with-Repeated-Values/m-p/695522#M212251</link>
      <description>&lt;P&gt;Maybe, since your code has a comment about "exploratory" a report of some kind is what you really want.&lt;/P&gt;
&lt;P&gt;So perhaps instead of &lt;/P&gt;
&lt;PRE&gt;Proc Transpose data=HIV_Data out=wide_EpiMetric prefix=epi_metric;
   by Country_Name;
   id epi_metric;
   var epi_value;
Run;&lt;/PRE&gt;
&lt;PRE&gt;Proc tabulate data=HIV_date;
   class country_name epi_metric;
   value epi_value;
   table country_name,
           epi_metric * epi_value*( min mean median max stddev)
          ;
run;&lt;/PRE&gt;
&lt;P&gt;Let's explore the data without making an ugly hard to use data set with practically impossible to remember and tiring to type variable names.&lt;/P&gt;</description>
      <pubDate>Fri, 30 Oct 2020 16:25:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-Data-with-Repeated-Values/m-p/695522#M212251</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-10-30T16:25:00Z</dc:date>
    </item>
  </channel>
</rss>

