<?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: use input statement with multiple variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/use-input-statement-with-multiple-variables/m-p/545705#M151024</link>
    <description>&lt;P&gt;You also suffer from a VERY BAD data model (wide).&lt;/P&gt;
&lt;P&gt;If you transpose this mostly unusable structure to the much better long format, you probably end up with just two variables that need conversion.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See Maxims 33, 19, 31, 22 (and probably some others)&lt;/P&gt;</description>
    <pubDate>Mon, 25 Mar 2019 07:22:17 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2019-03-25T07:22:17Z</dc:date>
    <item>
      <title>use input statement with multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-input-statement-with-multiple-variables/m-p/545667#M150997</link>
      <description>&lt;P&gt;Hello. I'm trying to convert multiple character variables to numeric variables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My data are as follows....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID pre_stress_visit1&amp;nbsp;&amp;nbsp;pre_stress_visit2&amp;nbsp;pre_stress_visit3&amp;nbsp;post_stress_visit1&amp;nbsp;post_stress_visit2&amp;nbsp;post_stress_visit3 pre_pain_visit1&lt;/P&gt;&lt;P&gt;A 12 10 9 10 8 7 53 ...&lt;/P&gt;&lt;P&gt;B 13 13 6 11 11 4 57 ...&lt;/P&gt;&lt;P&gt;C 13 12 8 10 13 7 55 ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the pre_stress_visitnumber and post_stress_visitnumber are recognized as character. So, i want to convert them into numeric variables&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Though I can convert each variables with input statement, like 'input(pre_stress_visit1, best32.)', it takes long time to do it. Is there a better way to convert them?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would really appreciate all your help. thanks.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Mar 2019 00:39:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-input-statement-with-multiple-variables/m-p/545667#M150997</guid>
      <dc:creator>km0927</dc:creator>
      <dc:date>2019-03-25T00:39:24Z</dc:date>
    </item>
    <item>
      <title>Re: use input statement with multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-input-statement-with-multiple-variables/m-p/545673#M151003</link>
      <description>&lt;P&gt;&lt;SPAN&gt;&amp;gt; Though I can convert each variables with input statement, like 'input(pre_stress_visit1, best32.)', it takes long time to do it. Is there a better way to convert them?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;That's the best way to convert them, and I doesn't take long at all. &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;What makes you think it takes long?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Mar 2019 02:31:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-input-statement-with-multiple-variables/m-p/545673#M151003</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-03-25T02:31:09Z</dc:date>
    </item>
    <item>
      <title>Re: use input statement with multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-input-statement-with-multiple-variables/m-p/545691#M151017</link>
      <description>&lt;P&gt;In fact, this is an example and i have more about 50-60 more variables to deal with.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If there is no other way, i will try to cope with it.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Mar 2019 05:49:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-input-statement-with-multiple-variables/m-p/545691#M151017</guid>
      <dc:creator>km0927</dc:creator>
      <dc:date>2019-03-25T05:49:46Z</dc:date>
    </item>
    <item>
      <title>Re: use input statement with multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-input-statement-with-multiple-variables/m-p/545692#M151018</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/233577"&gt;@km0927&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can always generate the code if you believe that's a better option than just explicitly writing the 60 statements.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  array chars {*} $15. id pre_stress_visit1  pre_stress_visit2 pre_stress_visit3 post_stress_visit1 post_stress_visit2 post_stress_visit3 pre_pain_visit1 (8*'25');
  output;
  stop;
run;

proc sql noprint;
  select 
    cats(name,'=','_',substrn(name,1,31))
    ,cats('_',substrn(name,1,31))
    ,cats(name,'=','input(_',substrn(name,1,31),',best32.);')
      into 
        :rename_list separated by ' '
        ,:drop_list separated by ' '
        ,:assign_list separated by ' '
  from dictionary.columns
  where libname='WORK' and memname='HAVE' and type='char' and upcase(name) not in ('ID')
  ;
quit;

data want;
  set have(
    rename=(&amp;amp;rename_list)
    );
  drop &amp;amp;drop_list;
  &amp;amp;assign_list;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Question is: Why do you end-up with all character in first place? Is reading the data into numerical variables from the beginning something you could influence?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Mar 2019 06:08:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-input-statement-with-multiple-variables/m-p/545692#M151018</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-03-25T06:08:51Z</dc:date>
    </item>
    <item>
      <title>Re: use input statement with multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-input-statement-with-multiple-variables/m-p/545704#M151023</link>
      <description>&lt;P&gt;"are recognized as character"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you use proc import to get data into SAS, replace it with a more robust method and use a data step that &lt;EM&gt;you&lt;/EM&gt; write to read the data.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Mar 2019 07:18:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-input-statement-with-multiple-variables/m-p/545704#M151023</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-03-25T07:18:22Z</dc:date>
    </item>
    <item>
      <title>Re: use input statement with multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-input-statement-with-multiple-variables/m-p/545705#M151024</link>
      <description>&lt;P&gt;You also suffer from a VERY BAD data model (wide).&lt;/P&gt;
&lt;P&gt;If you transpose this mostly unusable structure to the much better long format, you probably end up with just two variables that need conversion.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See Maxims 33, 19, 31, 22 (and probably some others)&lt;/P&gt;</description>
      <pubDate>Mon, 25 Mar 2019 07:22:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-input-statement-with-multiple-variables/m-p/545705#M151024</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-03-25T07:22:17Z</dc:date>
    </item>
    <item>
      <title>Re: use input statement with multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-input-statement-with-multiple-variables/m-p/545715#M151029</link>
      <description>&lt;P&gt;Thanks for letting me know the importance of 'proc import' format.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will take advice and transform it into another format.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Mar 2019 09:00:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-input-statement-with-multiple-variables/m-p/545715#M151029</guid>
      <dc:creator>km0927</dc:creator>
      <dc:date>2019-03-25T09:00:55Z</dc:date>
    </item>
    <item>
      <title>Re: use input statement with multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-input-statement-with-multiple-variables/m-p/545968#M151122</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/233577"&gt;@km0927&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello. I'm trying to convert multiple character variables to numeric variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My data are as follows....&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ID pre_stress_visit1&amp;nbsp;&amp;nbsp;pre_stress_visit2&amp;nbsp;pre_stress_visit3&amp;nbsp;post_stress_visit1&amp;nbsp;post_stress_visit2&amp;nbsp;post_stress_visit3 pre_pain_visit1&lt;/P&gt;
&lt;P&gt;A 12 10 9 10 8 7 53 ...&lt;/P&gt;
&lt;P&gt;B 13 13 6 11 11 4 57 ...&lt;/P&gt;
&lt;P&gt;C 13 12 8 10 13 7 55 ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;the pre_stress_visitnumber and post_stress_visitnumber are recognized as character. So, i want to convert them into numeric variables&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Though I can convert each variables with input statement, like 'input(pre_stress_visit1, best32.)', it takes long time to do it. Is there a better way to convert them?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would really appreciate all your help. thanks.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;PROC TRANSPOSE has features that make this easy and you can keep the variable labels.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data prepost;
   infile cards missover;
   input ID:$1.  (pre_stress_visit1 pre_stress_visit2 pre_stress_visit3 post_stress_visit1 post_stress_visit2 post_stress_visit3 pre_pain_visit1)($);
   attrib _all_ label='Test label';
   cards;
A 12 10 9 10 8 7 53 ...
B 13 13 6 11 11 4 57 ...
C 13 12 8 10 13 7 55 ...
;;;;
   run;
proc transpose data=prepost out=tall;
   by id;
   var p:;
   run;
proc print;
   run;
data tall;
   set tall;
   num1 = input(col1,f9.);
   run;
proc transpose data=tall out=prepostnum(drop=_name_);
   by id;
   var num1;
   run;
proc contents varnum;
proc print;
   run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/28192i97404B531F03F40F/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Mar 2019 21:33:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-input-statement-with-multiple-variables/m-p/545968#M151122</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2019-03-25T21:33:59Z</dc:date>
    </item>
  </channel>
</rss>

