sas proc

Reply
N/A
Posts: 0

sas proc

how we change a variable into observation
Super Contributor
Super Contributor
Posts: 3,174

Re: sas proc

If I am correct with your post message, here is one approach to convert a SAS dataset having multiple variables into a new SAS dataset, each observation/value transposed to a separate data observation (using a single variable).

For a given SAS dataset, using a SAS DATA step approach, input the SAS file with a SET stmt, declare a SAS variable, either numeric or character, and using an ARRAY, assign each element in the array to the declared variable and issue an output to generate a separate observation.


Recommend using the SAS support http://support.sas.com/ and its SEARCH facility for SAS-host documentation and technical/conference papers.

Scott Barry
SBBWorks, Inc.

SAS Language Concepts: DATA Step Processing
http://support.sas.com/documentation/cdl/en/lrcon/61722/HTML/default/a001281588.htm


A Hands-On Introduction to SAS® DATA Step Programming
Debbie Buck, D. B. & P. Associates, Houston, TX
http://www2.sas.com/proceedings/sugi30/134-30.pdf



* create some sample data to use with this exercise;
data temp;
input (x1-x5) ($);
datalines;
x1 x2 x3 x4 x5
run;
* convert a horizontal SAS dataset to vertical, one obs per variable/value combination. ;
data temp_vertical;
set temp;
array a_allvars (*) $ _all_;
* declare output var attribute
attrib x length=$2 label='transposed obs/var value';
do i=1 to dim(a_allvars);
x = a_allvars(i);
* putlog ">DIAG_INFO>" / _ALL_;
output;
end;
run;
N/A
Posts: 0

Re: sas proc

Hi
Thanks a lot for this information
Ask a Question
Discussion stats
  • 2 replies
  • 321 views
  • 0 likes
  • 2 in conversation