<?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 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Wide-to-Long/m-p/929382#M365690</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want(drop=Name Sex Age Height Weight i j);
 LENGTH Var_Name $ 32 Var_Value $ 40;
 set sashelp.class;
 array vn{2} $ Name Sex;          /* _CHARACTER_ */
 array vv{3}   Age Height Weight; /* _NUMERIC_   */
 do i=1 to dim(vn);
  Var_Name  = vname(vn(i));
  Var_Value = vn(i);
  output;
 end;
 do j=1 to dim(vv);
  Var_Name  = vname(vv(i));
  Var_Value = trim(left(put(vv(i),best16.)));
  output;
 end;
 run;
/* end of program */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
    <pubDate>Thu, 23 May 2024 10:31:51 GMT</pubDate>
    <dc:creator>sbxkoenk</dc:creator>
    <dc:date>2024-05-23T10:31:51Z</dc:date>
    <item>
      <title>Wide to Long</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Wide-to-Long/m-p/929381#M365689</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;Let's say that I want to create a data set based on sas_help.class data set.&lt;/P&gt;
&lt;P&gt;The new data set will have only 2 columns:&amp;nbsp; Var_name&amp;nbsp; , Var_Value&lt;/P&gt;
&lt;P&gt;What is the way to do it?&lt;/P&gt;
&lt;P&gt;I expect that the new data set will have 95 rows (because in&amp;nbsp;sas_help.class have 19 rows with 5 columns so 19*5=95)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thanks&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 10:12:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Wide-to-Long/m-p/929381#M365689</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2024-05-23T10:12:01Z</dc:date>
    </item>
    <item>
      <title>Re: Wide to Long</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Wide-to-Long/m-p/929382#M365690</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want(drop=Name Sex Age Height Weight i j);
 LENGTH Var_Name $ 32 Var_Value $ 40;
 set sashelp.class;
 array vn{2} $ Name Sex;          /* _CHARACTER_ */
 array vv{3}   Age Height Weight; /* _NUMERIC_   */
 do i=1 to dim(vn);
  Var_Name  = vname(vn(i));
  Var_Value = vn(i);
  output;
 end;
 do j=1 to dim(vv);
  Var_Name  = vname(vv(i));
  Var_Value = trim(left(put(vv(i),best16.)));
  output;
 end;
 run;
/* end of program */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Thu, 23 May 2024 10:31:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Wide-to-Long/m-p/929382#M365690</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2024-05-23T10:31:51Z</dc:date>
    </item>
    <item>
      <title>Re: Wide to Long</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Wide-to-Long/m-p/929392#M365698</link>
      <description>&lt;P&gt;Is this really a situation where it is a good idea to convert wide to long? Is this really even a "wide" data set?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't see how this is a good idea.&amp;nbsp;Having height and weight and age and sex and name in the same column in the resulting long data set doesn't seem to make sense to me, it's hard to see how this would be more useful for any SAS purpose than the original data set.&lt;/P&gt;</description>
      <pubDate>Thu, 23 May 2024 12:35:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Wide-to-Long/m-p/929392#M365698</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-05-23T12:35:11Z</dc:date>
    </item>
    <item>
      <title>Re: Wide to Long</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Wide-to-Long/m-p/929394#M365700</link>
      <description>&lt;P&gt;If the dataset has a key then use PROC TRANSPOSE with a BY statement.&lt;/P&gt;
&lt;P&gt;The key to SASHELP.CLASS is NAME.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=sashelp.class
  out=want(drop=name rename=(_name_=var_name col1=var_value))
;
  by name;
  var _all_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;Obs    var_name     var_value

  1     Name       Alfred
  2     Sex        M
  3     Age                  14
  4     Height               69
  5     Weight            112.5
  6     Name       Alice
  7     Sex        F
  8     Age                  13
  9     Height             56.5
 10     Weight               84
 11     Name       Barbara
 12     Sex        F
 13     Age                  13
 14     Height             65.3
 15     Weight               98
 16     Name       Carol
 17     Sex        F
 18     Age                  14
 19     Height             62.8
 20     Weight            102.5
&lt;/PRE&gt;
&lt;P&gt;If the dataset does not have a key then just add one.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  _key_+1;
  set sashelp.class;
run;

proc transpose data=want
  out=want(drop=_key_ rename=(_name_=var_name col1=var_value) where=(var_name ne '_key_'))
;
  by _key_;
  var _all_;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 May 2024 12:54:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Wide-to-Long/m-p/929394#M365700</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-05-23T12:54:26Z</dc:date>
    </item>
    <item>
      <title>Re: Wide to Long</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Wide-to-Long/m-p/929400#M365702</link>
      <description>&lt;P&gt;If this means you are considering creating a data set with a mix of character and "numeric" values in a single variable then you really need to specify what it would be used for as any "automagic" numeric to character conversion is rife will all sorts of result issues: widths, justification, number of decimal places and such.&lt;/P&gt;</description>
      <pubDate>Thu, 23 May 2024 13:58:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Wide-to-Long/m-p/929400#M365702</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-05-23T13:58:57Z</dc:date>
    </item>
    <item>
      <title>Re: Wide to Long</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Wide-to-Long/m-p/929698#M365789</link>
      <description>&lt;P&gt;I want to do it only for numeric variables and the target is to calculate the following output:&lt;/P&gt;
&lt;P&gt;Can you offer other way to calculate it using the original wide structure&amp;nbsp; and not convert to long??&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;


proc sql;
create table want_summary_Report as
select Var_Name,
       sum(case when Var_Value=. then 1 else 0 end ) as nr_Nulls,
       sum(case when Var_Value=0 then 1 else 0 end ) as nr_0,
       sum(case when Var_Value&amp;gt;0 then 1 else 0 end ) as nr_POS,
       sum(case when Var_Value&amp;lt;0 AND Var_Value=. then 1 else 0 end ) as nr_Neg,
	   count(distinct Var_Value) as nr_distinct_values
from Long_Structure_Numeric_Vars_Data
group by Var_Name
;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 26 May 2024 04:39:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Wide-to-Long/m-p/929698#M365789</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2024-05-26T04:39:12Z</dc:date>
    </item>
    <item>
      <title>Re: Wide to Long</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Wide-to-Long/m-p/929722#M365801</link>
      <description>&lt;P&gt;See your other topic thread :&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Procedures/nr-null-nr-zero-nr-POS-nr-NEG-for-each-numeric-var/td-p/929701" target="_blank"&gt;nr_null nr_zero,nr_POS,nr_NEG for each numeric var - SAS Support Communities&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Sun, 26 May 2024 12:21:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Wide-to-Long/m-p/929722#M365801</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2024-05-26T12:21:21Z</dc:date>
    </item>
  </channel>
</rss>

