Help using Base SAS procedures

String Function

Reply
Contributor
Posts: 34

String Function

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
Super Contributor
Super Contributor
Posts: 3,174

Re: String Function

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.
PROC Star
Posts: 1,555

Re: String Function

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;
Ask a Question
Discussion stats
  • 2 replies
  • 114 views
  • 0 likes
  • 3 in conversation