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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

New Learning Events in April

 

Join us for two new fee-based courses: Administrative Healthcare Data and SAS via Live Web Monday-Thursday, April 24-27 from 1:00 to 4:30 PM ET each day. And Administrative Healthcare Data and SAS: Hands-On Programming Workshop via Live Web on Friday, April 28 from 9:00 AM to 5:00 PM ET.

LEARN MORE

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