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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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