<?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 Transpose then Query in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Transpose-then-Query/m-p/260341#M18163</link>
    <description>&lt;P&gt;Hi there, I'm new to the SAS forums, but been using Enterprise Guide 5.1 for about a year now (soon upgrading to the latest EG).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a project where I transpose month by month data from vertical to horizontal, thereby creating a column for each month. Obviously this adds a new column each month, which I then have to manually add to the query that follows it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm wondering whether there is any way to automatically add these new columns to my query, or alternatively, to tranpose without generating the "Source" and "Label" columns. I'm a new user so while not being afraid of using code to do this, I have zero background in coding (hoping to learn this soon though)!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance for any help.&lt;/P&gt;</description>
    <pubDate>Thu, 31 Mar 2016 08:25:27 GMT</pubDate>
    <dc:creator>Seb_A_Sanders</dc:creator>
    <dc:date>2016-03-31T08:25:27Z</dc:date>
    <item>
      <title>Transpose then Query</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Transpose-then-Query/m-p/260341#M18163</link>
      <description>&lt;P&gt;Hi there, I'm new to the SAS forums, but been using Enterprise Guide 5.1 for about a year now (soon upgrading to the latest EG).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a project where I transpose month by month data from vertical to horizontal, thereby creating a column for each month. Obviously this adds a new column each month, which I then have to manually add to the query that follows it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm wondering whether there is any way to automatically add these new columns to my query, or alternatively, to tranpose without generating the "Source" and "Label" columns. I'm a new user so while not being afraid of using code to do this, I have zero background in coding (hoping to learn this soon though)!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance for any help.&lt;/P&gt;</description>
      <pubDate>Thu, 31 Mar 2016 08:25:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Transpose-then-Query/m-p/260341#M18163</guid>
      <dc:creator>Seb_A_Sanders</dc:creator>
      <dc:date>2016-03-31T08:25:27Z</dc:date>
    </item>
    <item>
      <title>Re: Transpose then Query</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Transpose-then-Query/m-p/260351#M18164</link>
      <description>&lt;P&gt;Why do you require the transpsed table? &amp;nbsp;It is easier to work with the normalised strcuture - hence why its probably in that form already. &amp;nbsp;You have hit on eof the issues of transposed data - i.e. knowing what a table where the structure keeps changing looks like, the other issue is that eventually, you will have so many columns the data is not reviewable - I mean how many people really scroll to the right through lots of columns?&lt;/P&gt;
&lt;P&gt;I suppose if you really had to work with this - say it was for a report (i.e not for further processing), then you could either do:&lt;/P&gt;
&lt;PRE&gt;proc sql noprint;
  select distinct NAME 
  into    :V separated by " "
  from   DICTIONARY.COLUMNS
  where LIBNAME="&amp;lt;your_libname&amp;gt;"
    and  substr(MEMNAME,1,3)="ABC";
quit;&lt;/PRE&gt;
&lt;P&gt;The above would give you a macro variable separated by spaces, of each variable in &amp;lt;your_libname&amp;gt;.ABCxyz - just assumed a prefix of ABC here.&lt;/P&gt;
&lt;P&gt;Or if you need to process the data, then arrays - make sure each of your column names is prefixed the same, i.e. don't put "data" as the variable name e.g:&lt;/P&gt;
&lt;PRE&gt;proc transpose data=have out=t_have prefix="COL";
  by &amp;lt;by_vars&amp;gt;;
  var &amp;lt;var&amp;gt;;
  id month;
  idlabel month;
run;&lt;/PRE&gt;
&lt;P&gt;Your dataset will then look like:&lt;/P&gt;
&lt;P&gt;COLJAN &amp;nbsp; COLMAR COL...&lt;/P&gt;
&lt;P&gt;You can then easily refer to these variables:&lt;/P&gt;
&lt;PRE&gt;data tmp; 
  set t_have;
  array months{3} col:;
  ...
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 31 Mar 2016 09:22:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Transpose-then-Query/m-p/260351#M18164</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-03-31T09:22:18Z</dc:date>
    </item>
    <item>
      <title>Re: Transpose then Query</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Transpose-then-Query/m-p/260371#M18165</link>
      <description>&lt;P&gt;While keeping the structure vertical&amp;nbsp;is usually easier to work with you don't describe the query that follows making it rather difficult to quess how it uses the transpose data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What are SOURCE and LABEL how are the new (month) variables named? &amp;nbsp;Do you use PROC TRANSPOSE?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The answer could be as simple as, "use a SAS Variable List" but you don't give enough information to know.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you show example input to transpose and output and describe the query?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Mar 2016 11:25:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Transpose-then-Query/m-p/260371#M18165</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2016-03-31T11:25:57Z</dc:date>
    </item>
    <item>
      <title>Re: Transpose then Query</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Transpose-then-Query/m-p/260377#M18166</link>
      <description>&lt;P&gt;I will leave the discussion on why to transpose to others. This is my suggestion assuming you made all the right choices &lt;img id="manwink" class="emoticon emoticon-manwink" src="https://communities.sas.com/i/smilies/16x16_man-wink.png" alt="Man Wink" title="Man Wink" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In EG you can create a query with a left outer&amp;nbsp;(or in my case right) join between a table of all months and your data such that all missing monts are added to the data with all other columns missing. Then do the transpose. You should then get a var for every month. EG would create such a join as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
   CREATE TABLE WORK.QUERY_FOR_TEST AS 
   SELECT t2.month, 
          t1.dept, 
          t1.value
      FROM WORK.TEST t1
           RIGHT JOIN WORK.MONTHS t2 ON (t1.month = t2.month);
QUIT;&lt;/CODE&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;BR /&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;Hope this helps,&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;- Jan.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Mar 2016 12:25:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Transpose-then-Query/m-p/260377#M18166</guid>
      <dc:creator>jklaverstijn</dc:creator>
      <dc:date>2016-03-31T12:25:18Z</dc:date>
    </item>
  </channel>
</rss>

