BookmarkSubscribeRSS Feed
DPraba79
Calcite | Level 5
Hi,

I have a dataset with two obs and one varibale. The variable name is A and the values are "USA SAS" & "EARTH WORLD". I need to create a output datset like below.

INPUT:

A
---
USA SAS
EARTH WORLD

OUTPUT :
USA EARTH
----- ----------
SAS .
. WORLD

The first part of my input variable A should go to output varible and the second part of the input variable will be VALUE of the output variable, Could you please let me know how to do this?

Thanks
2 REPLIES 2
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Investigate using the SCAN function (DATA step, SAS variable assignment) and also the PROC TRANSPOSE procedure. The SAS support http://support.sas.com/ has SAS-hosted documentation for this topic area.

Scott Barry
SBBWorks, Inc.
ChrisNZ
Tourmaline | Level 20
Alternatively you can try this.
Spaces in sas variable names must be used with caution, so I used a _ instead.
You can use a space in the variable label if you want.

[pre]
data SAMPLE;
infile cards truncover;
input A $16.;
cards;
USA SAS
EARTH WORLD
run;
data STEP1;
set SAMPLE;
length NAME $16; * set variable name length;
retain NAME; * variable name is built across several obs;
VALUE=scan(A,2); * build values;
NAME=catx('_',NAME,scan(A,1)); * build variable name;
call symput('varname', NAME); * save variable name;
run;
data STEP2;
set STEP1 (keep=VALUE rename=(VALUE=&varname)); * use variable name;
run;

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 605 views
  • 0 likes
  • 3 in conversation