<?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: Adding Variables to SAS after importing an excel document in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Adding-Variables-to-SAS-after-importing-an-excel-document/m-p/516931#M139659</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/248904"&gt;@Chris_C&lt;/a&gt;&amp;nbsp;what is the format of your input file (xlsx or csv?) . If it is in excel native format you may have to use Proc Import to create a sas dataset and use the datastep for further processing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Post the code that that you have already tried .&lt;/P&gt;</description>
    <pubDate>Thu, 29 Nov 2018 02:00:45 GMT</pubDate>
    <dc:creator>r_behata</dc:creator>
    <dc:date>2018-11-29T02:00:45Z</dc:date>
    <item>
      <title>Adding Variables to SAS after importing an excel document</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-Variables-to-SAS-after-importing-an-excel-document/m-p/516927#M139657</link>
      <description>&lt;P&gt;&amp;nbsp;While working with an excel document I want to condense the data into one row&amp;nbsp;by adding variables Q1_Hours and Q1_Percent through Q6_Hours and Q6_Percent. I am confused because the normal ways to create variables through the INPUT after the data step is not working. One section of the data looks as follows (In the excel document). Anyone have any advice or tips?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Year&lt;/TD&gt;&lt;TD&gt;Exam&lt;/TD&gt;&lt;TD&gt;Day&lt;/TD&gt;&lt;TD&gt;Time&lt;/TD&gt;&lt;TD&gt;Type&lt;/TD&gt;&lt;TD&gt;Q1&lt;/TD&gt;&lt;TD&gt;Q2&lt;/TD&gt;&lt;TD&gt;Q3&lt;/TD&gt;&lt;TD&gt;Q4&lt;/TD&gt;&lt;TD&gt;Q5&lt;/TD&gt;&lt;TD&gt;Q6&lt;/TD&gt;&lt;TD&gt;Overall&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;Mid&lt;/TD&gt;&lt;TD&gt;Hours&lt;/TD&gt;&lt;TD&gt;0.0&lt;/TD&gt;&lt;TD&gt;13.3&lt;/TD&gt;&lt;TD&gt;7.5&lt;/TD&gt;&lt;TD&gt;0.0&lt;/TD&gt;&lt;TD&gt;0.0&lt;/TD&gt;&lt;TD&gt;7.5&lt;/TD&gt;&lt;TD&gt;28.3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Percent&lt;/TD&gt;&lt;TD&gt;0.0&lt;/TD&gt;&lt;TD&gt;98.6&lt;/TD&gt;&lt;TD&gt;38.9&lt;/TD&gt;&lt;TD&gt;0.0&lt;/TD&gt;&lt;TD&gt;0.0&lt;/TD&gt;&lt;TD&gt;57.3&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;32.5&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Thu, 29 Nov 2018 01:18:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-Variables-to-SAS-after-importing-an-excel-document/m-p/516927#M139657</guid>
      <dc:creator>Chris_C</dc:creator>
      <dc:date>2018-11-29T01:18:22Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Variables to SAS after importing an excel document</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-Variables-to-SAS-after-importing-an-excel-document/m-p/516931#M139659</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/248904"&gt;@Chris_C&lt;/a&gt;&amp;nbsp;what is the format of your input file (xlsx or csv?) . If it is in excel native format you may have to use Proc Import to create a sas dataset and use the datastep for further processing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Post the code that that you have already tried .&lt;/P&gt;</description>
      <pubDate>Thu, 29 Nov 2018 02:00:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-Variables-to-SAS-after-importing-an-excel-document/m-p/516931#M139659</guid>
      <dc:creator>r_behata</dc:creator>
      <dc:date>2018-11-29T02:00:45Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Variables to SAS after importing an excel document</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-Variables-to-SAS-after-importing-an-excel-document/m-p/516933#M139660</link>
      <description>&lt;P&gt;The file is .xlsx and here is the code I am using&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/223452"&gt;@r_behata&lt;/a&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC IMPORT OUT= WORK.ExamBDay4_0&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DATAFILE= "\\Client\D$\SASDATA\Year_2_Exam_B_Day_4_0-morning.xlsx"&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DBMS=EXCELCS REPLACE;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RANGE="Sheet1$";&lt;BR /&gt;RUN;&lt;BR /&gt;DATA ExamBDay4_0;&lt;/P&gt;&lt;P&gt;SET ExamBDay4_0;&lt;BR /&gt;INPUT Q1_Hours Q1 Percent Q2_Hours Q2_Percent Q3_Hours Q3_Percent Q4_Hours Q4_Percent Q5_Hours Q5_Percent Q6_Hours Q6_Percent Overall_Hours Overall_Percent;&lt;BR /&gt;RUN;&lt;BR /&gt;PROC PRINT DATA=ExamBDay4_0;&lt;BR /&gt;RUN;QUIT;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Nov 2018 02:35:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-Variables-to-SAS-after-importing-an-excel-document/m-p/516933#M139660</guid>
      <dc:creator>Chris_C</dc:creator>
      <dc:date>2018-11-29T02:35:25Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Variables to SAS after importing an excel document</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-Variables-to-SAS-after-importing-an-excel-document/m-p/516937#M139661</link>
      <description>&lt;P&gt;The INPUT statement is for reading values from text (file or in-line data lines).&amp;nbsp; So it will not be of any help in this case since you do not have any text to read. The PROC IMPORT step will have already created a dataset for you to use.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To change/create variables just use assignment statements.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Show an example of what the data that PROC IMPORT created looks like.&lt;/P&gt;
&lt;P&gt;Your picture of the layout of the Excel makes it look like you do not have key values on all observations so you might first need to fill those in before attempting to transpose the data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also why do you want to put the data into such a wide format? It probably will be easier to work with if you created a&amp;nbsp;tall format instead.&lt;/P&gt;
&lt;P&gt;Something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  input Year Exam $ Day Time $ Period $ Hours Percent ;
cards;
2 B 4 Mid Q1 0 0
2 B 4 Mid Q2 13.3 98.6
...
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Nov 2018 03:30:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-Variables-to-SAS-after-importing-an-excel-document/m-p/516937#M139661</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-11-29T03:30:53Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Variables to SAS after importing an excel document</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-Variables-to-SAS-after-importing-an-excel-document/m-p/516940#M139662</link>
      <description>&lt;P&gt;The Data is not mine I am just doing some volunteer work to help an old high school teacher out so I am hesitant to alter the data that was provided to me. There are multiple excel sheets for classes so I planned on stacking them together and the easiest way to read would be if they were in the wide rows. &amp;nbsp; &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Obs Year Exam Day Time Type   Q1 Q2   Q3  Q4  Q5  Q6  Overall 
1 .   .               Percent 0  29.7 0    0   0  0    4.9 
2     2  B   2    Mid   Hours 0  5.8  0    0   0  0    5.8 

&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Nov 2018 03:58:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-Variables-to-SAS-after-importing-an-excel-document/m-p/516940#M139662</guid>
      <dc:creator>Chris_C</dc:creator>
      <dc:date>2018-11-29T03:58:13Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Variables to SAS after importing an excel document</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-Variables-to-SAS-after-importing-an-excel-document/m-p/516975#M139671</link>
      <description>&lt;P&gt;Thats typical garbage Excel data unfortunately.&amp;nbsp; You will need to do some post processing to get it into a working state.&amp;nbsp; So you have this:&lt;/P&gt;
&lt;PRE&gt;proc import out=work.exambday4_0
            datafile="\\Client\D$\SASDATA\Year_2_Exam_B_Day_4_0-morning.xlsx"
            bdms=excelcs replace;
     range="Sheet1$";
run;&lt;/PRE&gt;
&lt;P&gt;And note how I use the code window - its the {i} above post area - and don't code all in shouting.&lt;/P&gt;
&lt;P&gt;To get the data you show there.&amp;nbsp; First you need to clear up the missing year/exam/day/time data (done by coalesce() function below) and merge the two rows so you have one row.&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table want as 
  select coalesce(a.year,b.year) as year,
         coalesce(a.exam,b.exam) as exam,
         coalesce(a.day,b.day) as day,
         coalesce(a.time,b.time) as time,
         a.q1 as p_q1,
         a.q2 as p_q2,
         a.q3 as p_q3,
         a.q4 as p_q4,
         a.q5 as p_q5,
         a.q6 as p_q6,
         a.overall as overall_p,
         b.q1 as h_q1,
         b.q2 as h_q2,
         b.q3 as h_q3,
         b.q4 as h_q4,
         b.q5 as h_q5,
         b.q6 as h_q6,
         b.overall as overall_h
  from   (select * from have where type="Percent") a
  full join (select * from have where type="Hours") b
  on     1=1;
quit;
&lt;/PRE&gt;
&lt;P&gt;You can then do further processsing on this data, such as stacking all sheets (with which you have done the above) and summing something like:&lt;/P&gt;
&lt;PRE&gt;data want;
  set want;
  hours=sum(of h_:);&lt;BR /&gt;  perc=sum(of p_:);&lt;BR /&gt;run;&lt;/PRE&gt;
&lt;P&gt;Take it as a good example of why not to use Excel for data storage!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Nov 2018 09:50:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-Variables-to-SAS-after-importing-an-excel-document/m-p/516975#M139671</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-11-29T09:50:17Z</dc:date>
    </item>
  </channel>
</rss>

