<?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: Wide to Long for numeric VARS only in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Wide-to-Long-for-numeric-VARS-only/m-p/929404#M365703</link>
    <description>&lt;P&gt;By default Proc Transpose will use all numeric values as Var variables if a Var statement is not included.&lt;/P&gt;
&lt;P&gt;So you might look at:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Proc transpose data=sashelp.class&lt;BR /&gt;out=trans (keep=_name_ col1 rename=(_name_=var_name col1=var_value));&lt;BR /&gt;&lt;STRIKE&gt;by _character_ notsorted;&lt;/STRIKE&gt;&lt;BR /&gt;by _all_ notsorted;&lt;BR /&gt;run; &lt;/PRE&gt;
&lt;P&gt;for the example. For a truly lazy way to code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However if the combination of all the &lt;STRIKE&gt;_character_&lt;/STRIKE&gt;&amp;nbsp; _All_ variables does not uniquely identify a record (i.e. there are duplicates and the data has been sorted (grouped) by them) the output will not include var_values for the duplicated by variable combinations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;CAUTION: &lt;/STRONG&gt;If the data set has Date, time and datetime values may be difficult to use with the single format that the resulting var_value column will have.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 23 May 2024 16:44:32 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2024-05-23T16:44:32Z</dc:date>
    <item>
      <title>Wide to Long for numeric VARS only</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Wide-to-Long-for-numeric-VARS-only/m-p/929385#M365692</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;With continue to previous post,&lt;/P&gt;
&lt;P&gt;I want to create a new data set based on sashelp.class data set .&lt;/P&gt;
&lt;P&gt;I want that in new data set will have 2 columns; Var_name ,Var_value.&lt;/P&gt;
&lt;P&gt;I want it to be done only for numeric vars.&lt;/P&gt;
&lt;P&gt;I want to identify the numeric vars automatically (Because I want to apply this code on different data sets)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc sql;
create table numeric_Vars as
select libname, memname, name, type, length,
format, informat, label
from dictionary.columns
where libname = 'SASHELP' and memname = 'CLASS' and upcase(type) = 'NUM'
;
quit;


proc sql noprint;
select name into : Numeric_Vars_List SEPARATED by ' '
from numeric_Vars
;
quit;
%put &amp;amp;Numeric_Vars_List.; /**Age Height Weight**/


proc sql noprint;
select count(*) as nr_numeric_Vars into :nr_numeric_Vars
from numeric_Vars
;
quit;
%put &amp;amp;nr_numeric_Vars.;


data Long_Structure_Numeric_Vars_Data;
set sashelp.class;
array vv{&amp;amp;nr_numeric_Vars.}   &amp;amp;Numeric_Vars_List.; /* _NUMERIC_   */
do j=1 to dim(vv);
Var_Name  = vname(vv(i));
Var_Value = vv(i);
output;
end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The error in log is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;INFO: Character variables have defaulted to a length of 200 at the places given by: (Line):(Column). Truncation can result.
      31:1     Var_Name
NOTE: Variable i is uninitialized.
ERROR: Array subscript out of range at line 31 column 19.
Name=Alfred Sex=M Age=14 Height=69 Weight=112.5 j=1 Var_Name=  i=. Var_Value=  _ERROR_=1 _N_=1
NOTE: The SAS System stopped processing this step because of errors.
NOTE: There were 1 observations read from the data set SASHELP.CLASS.
WARNING: The data set WORK.LONG_STRUCTURE_NUMERIC_VARS_DATA may be incomplete.  When this step was stopped there were 0 
         observations and 9 variables.
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 May 2024 11:26:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Wide-to-Long-for-numeric-VARS-only/m-p/929385#M365692</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2024-05-23T11:26:23Z</dc:date>
    </item>
    <item>
      <title>Re: Wide to Long for numeric VARS only</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Wide-to-Long-for-numeric-VARS-only/m-p/929386#M365693</link>
      <description>&lt;PRE&gt;NOTE: Variable i is uninitialized.&lt;/PRE&gt;
&lt;P&gt;You can't use a variable named I until it has been defined and given a value. You have not given it a value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 May 2024 11:35:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Wide-to-Long-for-numeric-VARS-only/m-p/929386#M365693</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-05-23T11:35:10Z</dc:date>
    </item>
    <item>
      <title>Re: Wide to Long for numeric VARS only</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Wide-to-Long-for-numeric-VARS-only/m-p/929388#M365695</link>
      <description>&lt;P&gt;Great! solution is fine now&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc sql;
create table numeric_Vars as
select libname, memname, name, type, length,
format, informat, label
from dictionary.columns
where libname = 'SASHELP' and memname = 'CLASS' and upcase(type) = 'NUM'
;
quit;


proc sql noprint;
select name into : Numeric_Vars_List SEPARATED by ' '
from numeric_Vars
;
quit;
%put &amp;amp;Numeric_Vars_List.; /**Age Height Weight**/


proc sql noprint;
select count(*) as nr_numeric_Vars into :nr_numeric_Vars
from numeric_Vars
;
quit;
%put &amp;amp;nr_numeric_Vars.;


data Long_Structure_Numeric_Vars_Data(DROP=&amp;amp;Numeric_Vars_List. J);
set sashelp.class(KEEP=&amp;amp;Numeric_Vars_List.);
array vv{&amp;amp;nr_numeric_Vars.}   &amp;amp;Numeric_Vars_List.; /* _NUMERIC_   */
do j=1 to dim(vv);
Var_Name  = vname(vv(j));
Var_Value =vv(j);
output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 May 2024 11:49:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Wide-to-Long-for-numeric-VARS-only/m-p/929388#M365695</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2024-05-23T11:49:18Z</dc:date>
    </item>
    <item>
      <title>Re: Wide to Long for numeric VARS only</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Wide-to-Long-for-numeric-VARS-only/m-p/929393#M365699</link>
      <description>&lt;P&gt;Why are you working so hard?&amp;nbsp; &amp;nbsp;No code generation is needed.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  length var_name $32 var_value 8 ;
  set sashelp.class;
  array _num_ _numeric_;
  do _n_=2 to dim(_num_);
    var_name = vname(_num_[_n_]);
    var_value = _num_[_n_];
    output;
  end;
  keep var_name var_value;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The resulting data is the same:&lt;/P&gt;
&lt;PRE&gt;Observation Summary                                                                                                                 
                                                                                                                                    
Observation      Base  Compare                                                                                                      
                                                                                                                                    
First Obs           1        1                                                                                                      
Last  Obs          57       57                                                                                                      
                                                                                                                                    
Number of Observations in Common: 57.                                                                                               
Total Number of Observations Read from WORK.WANT: 57.                                                                               
Total Number of Observations Read from WORK.LONG_STRUCTURE_NUMERIC_VARS_DATA: 57.                                                   
                                                                                                                                    
Number of Observations with Some Compared Variables Unequal: 0.                                                                     
Number of Observations with All Compared Variables Equal: 57.                                                                       
                                                                                                                                    
NOTE: No unequal values were found. All values compared are exactly equal.                                                          &lt;/PRE&gt;
&lt;P&gt;The only difference is that my code makes the VAR_NAME variable shorter since SAS names can only be 32 bytes long.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 May 2024 12:41:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Wide-to-Long-for-numeric-VARS-only/m-p/929393#M365699</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-05-23T12:41:05Z</dc:date>
    </item>
    <item>
      <title>Re: Wide to Long for numeric VARS only</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Wide-to-Long-for-numeric-VARS-only/m-p/929404#M365703</link>
      <description>&lt;P&gt;By default Proc Transpose will use all numeric values as Var variables if a Var statement is not included.&lt;/P&gt;
&lt;P&gt;So you might look at:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Proc transpose data=sashelp.class&lt;BR /&gt;out=trans (keep=_name_ col1 rename=(_name_=var_name col1=var_value));&lt;BR /&gt;&lt;STRIKE&gt;by _character_ notsorted;&lt;/STRIKE&gt;&lt;BR /&gt;by _all_ notsorted;&lt;BR /&gt;run; &lt;/PRE&gt;
&lt;P&gt;for the example. For a truly lazy way to code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However if the combination of all the &lt;STRIKE&gt;_character_&lt;/STRIKE&gt;&amp;nbsp; _All_ variables does not uniquely identify a record (i.e. there are duplicates and the data has been sorted (grouped) by them) the output will not include var_values for the duplicated by variable combinations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;CAUTION: &lt;/STRONG&gt;If the data set has Date, time and datetime values may be difficult to use with the single format that the resulting var_value column will have.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 May 2024 16:44:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Wide-to-Long-for-numeric-VARS-only/m-p/929404#M365703</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-05-23T16:44:32Z</dc:date>
    </item>
  </channel>
</rss>

