BookmarkSubscribeRSS Feed
deleted_user
Not applicable
how we change a variable into observation
2 REPLIES 2
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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;
deleted_user
Not applicable
Hi
Thanks a lot for this information

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Health and Life Sciences Learning

 

Need courses to help you with SAS Life Sciences Analytics Framework, SAS Health Cohort Builder, or other topics? Check out the Health and Life Sciences learning path for all of the offerings.

LEARN MORE

Discussion stats
  • 2 replies
  • 970 views
  • 0 likes
  • 2 in conversation