<?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 How to save OUT results in a name variable in SAS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-save-OUT-results-in-a-name-variable-in-SAS/m-p/572575#M161585</link>
    <description>&lt;P&gt;I tried to convert wide format data to long format but it only gives me the result in output format. I would like to save the output of this in a variable name (sirstvt_long) and be able to print it as print(sirstvt_long). Also, I would like to drop Subject columns and sort this table by instrument column (starting with I1, I2,..I5). How do I do this in SAS?&amp;nbsp; Sorry I am new to SAS and your help would be appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data sirstvt;&lt;BR /&gt;  infile 'https://www.itl.nist.gov/div898/strd/anova/SiRstvt.dat' url firstobs=61 truncover;&lt;BR /&gt;  input I1-I5 ;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data sirstvt;&lt;BR /&gt;set sirstvt;&lt;BR /&gt;Subject+1; &lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc transpose data=sirstvt &lt;BR /&gt;   OUT=sirstvt_long(rename=(Col1=Resistance)) name=Instrument;                    &lt;BR /&gt;   by Subject;                   /** for each subject **/&lt;BR /&gt;   var I1 I2 I3 I4 I5; /** make a row for these variables **/&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;print(sirstvt_long);&lt;/PRE&gt;&lt;P&gt;Result I want should be in this format:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Instrument Resistance&lt;BR /&gt;1 196.3052&lt;BR /&gt;1 196.1240&lt;BR /&gt;1 196.1890&lt;BR /&gt;1 196.2569&lt;BR /&gt;1 196.3403&lt;BR /&gt;2 196.3042&lt;BR /&gt;2 196.3825&lt;BR /&gt;2 196.1669&lt;BR /&gt;2 196.3257&lt;BR /&gt;2 196.0422&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 11 Jul 2019 01:07:54 GMT</pubDate>
    <dc:creator>mapk</dc:creator>
    <dc:date>2019-07-11T01:07:54Z</dc:date>
    <item>
      <title>How to save OUT results in a name variable in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-save-OUT-results-in-a-name-variable-in-SAS/m-p/572575#M161585</link>
      <description>&lt;P&gt;I tried to convert wide format data to long format but it only gives me the result in output format. I would like to save the output of this in a variable name (sirstvt_long) and be able to print it as print(sirstvt_long). Also, I would like to drop Subject columns and sort this table by instrument column (starting with I1, I2,..I5). How do I do this in SAS?&amp;nbsp; Sorry I am new to SAS and your help would be appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data sirstvt;&lt;BR /&gt;  infile 'https://www.itl.nist.gov/div898/strd/anova/SiRstvt.dat' url firstobs=61 truncover;&lt;BR /&gt;  input I1-I5 ;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data sirstvt;&lt;BR /&gt;set sirstvt;&lt;BR /&gt;Subject+1; &lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc transpose data=sirstvt &lt;BR /&gt;   OUT=sirstvt_long(rename=(Col1=Resistance)) name=Instrument;                    &lt;BR /&gt;   by Subject;                   /** for each subject **/&lt;BR /&gt;   var I1 I2 I3 I4 I5; /** make a row for these variables **/&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;print(sirstvt_long);&lt;/PRE&gt;&lt;P&gt;Result I want should be in this format:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Instrument Resistance&lt;BR /&gt;1 196.3052&lt;BR /&gt;1 196.1240&lt;BR /&gt;1 196.1890&lt;BR /&gt;1 196.2569&lt;BR /&gt;1 196.3403&lt;BR /&gt;2 196.3042&lt;BR /&gt;2 196.3825&lt;BR /&gt;2 196.1669&lt;BR /&gt;2 196.3257&lt;BR /&gt;2 196.0422&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jul 2019 01:07:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-save-OUT-results-in-a-name-variable-in-SAS/m-p/572575#M161585</guid>
      <dc:creator>mapk</dc:creator>
      <dc:date>2019-07-11T01:07:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to save OUT results in a name variable in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-save-OUT-results-in-a-name-variable-in-SAS/m-p/572580#M161587</link>
      <description>&lt;P&gt;Without knowing the content of you in file I can't actually run the first part of the code to verify it. But assuming that that one works, instead of your last line you could replace it with the following code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*Sort the table by your I(n) variables and drop the column subject; 

proc sort 	data=sirstvt_long 
		out=sirstvt_long_2 (drop=subject);
	by I1 I2 I3 I4 I5;
run;

*Print the table, but don't show row number in the output. Also use labels if there are any.;
proc print data=sirstvt_long_2 noobs label;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This will print the table on screen. Do you want it written to a space separated text file?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jul 2019 02:18:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-save-OUT-results-in-a-name-variable-in-SAS/m-p/572580#M161587</guid>
      <dc:creator>heffo</dc:creator>
      <dc:date>2019-07-11T02:18:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to save OUT results in a name variable in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-save-OUT-results-in-a-name-variable-in-SAS/m-p/572582#M161588</link>
      <description>Not sure why I am still getting this error:&lt;BR /&gt;1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;&lt;BR /&gt;72&lt;BR /&gt;73 proc sort data=sirstvt_long out=sirstvt_long_2 (drop=subject);&lt;BR /&gt;74 by I1 I2 I3 I4 I5;&lt;BR /&gt;ERROR: Variable I1 not found.&lt;BR /&gt;ERROR: Variable I2 not found.&lt;BR /&gt;ERROR: Variable I3 not found.&lt;BR /&gt;ERROR: Variable I4 not found.&lt;BR /&gt;ERROR: Variable I5 not found.&lt;BR /&gt;75 run;&lt;BR /&gt;&lt;BR /&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;WARNING: The data set WORK.SIRSTVT_LONG_2 may be incomplete. When this step was stopped there were 0 observations and 0 variables.&lt;BR /&gt;WARNING: Data set WORK.SIRSTVT_LONG_2 was not replaced because this step was stopped.&lt;BR /&gt;NOTE: PROCEDURE SORT used (Total process time):&lt;BR /&gt;real time 0.07 seconds&lt;BR /&gt;cpu time 0.01 seconds</description>
      <pubDate>Thu, 11 Jul 2019 01:19:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-save-OUT-results-in-a-name-variable-in-SAS/m-p/572582#M161588</guid>
      <dc:creator>mapk</dc:creator>
      <dc:date>2019-07-11T01:19:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to save OUT results in a name variable in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-save-OUT-results-in-a-name-variable-in-SAS/m-p/572585#M161590</link>
      <description>&lt;P&gt;Instead of&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	by I1 I2 I3 I4 I5;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I had to use&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;by Instrument&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;It worked now. Thanks a lot.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jul 2019 01:30:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-save-OUT-results-in-a-name-variable-in-SAS/m-p/572585#M161590</guid>
      <dc:creator>mapk</dc:creator>
      <dc:date>2019-07-11T01:30:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to save OUT results in a name variable in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-save-OUT-results-in-a-name-variable-in-SAS/m-p/572586#M161591</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/281165"&gt;@mapk&lt;/a&gt;&amp;nbsp;:&lt;/P&gt;
&lt;P&gt;For the public record, the data extracted from the URL you're referencing is tantamount to:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sirstvt ;                               
  input i1-i5 ;                              
  cards ;                                    
196.3052 196.3042 196.1303 196.2795 196.2119 
196.124  196.3825 196.2005 196.1748 196.1051 
196.189  196.1669 196.2889 196.1494 196.185  
196.2569 196.3257 196.0343 196.1485 196.0052 
196.3403 196.0422 196.1811 195.9885 196.209  
run ;                                        
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To get what you want as shown in your output sample, there's no need to sort:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sirstvt ;                                                                               
  infile 'https://www.itl.nist.gov/div898/strd/anova/SiRstvt.dat' url firstobs=61 truncover ;
  input i1-i5 ;                                                                              
  put i1-i5 ;                                                                                
run ;                                                                                        
                                                                                             
proc transpose out = _sirstvt ;                                                              
run ;                                                                                        
                                                                                             
data sirstvt_long (keep = Instrument Resistance) ;                                           
  set _sirstvt ;                                                                             
  array col col: ;                                                                           
  Instrument = _n_ ;                                                                         
  do over col ;                                                                              
    Resistance = col ;                                                                       
    output ;                                                                                 
  end ;                                                                                      
  format Resistance 8.4 ;                                                                    
run ;                                                                                        
                                                                                             
proc print data = sirstvt_long noobs ;                                                       
run ;                                                                                        
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jul 2019 02:14:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-save-OUT-results-in-a-name-variable-in-SAS/m-p/572586#M161591</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-07-11T02:14:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to save OUT results in a name variable in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-save-OUT-results-in-a-name-variable-in-SAS/m-p/572587#M161592</link>
      <description>&lt;P&gt;I read your code a bit to fast. Yes, I1-I5 does not exist anymore, they have been transposed to the variable Instrument.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jul 2019 02:20:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-save-OUT-results-in-a-name-variable-in-SAS/m-p/572587#M161592</guid>
      <dc:creator>heffo</dc:creator>
      <dc:date>2019-07-11T02:20:13Z</dc:date>
    </item>
  </channel>
</rss>

