DATA Step, Macro, Functions and more

Create dataset uing scan function

Reply
N/A
Posts: 0

Create dataset uing scan function

Hi All,
I have one dataset (data1) with single observation say: something|to|be|written|here.

I have to create other dataset(data2) from above dataset(data1) with below observations:
something
to
be
written
here

I have to do this using scan function only.

Please Help!!!


Thanks,
Hema Tandon
Respected Advisor
Posts: 3,889

Re: Create dataset uing scan function

Hema

You only learn it by solving it yourself - or at least invest some time trying to find out.
You'll find everything in the Online Doc and there are normally also examples.

But let's assume you waited too long before starting with work....

data have;
var="something|to|be|written|here.";
run;
data want;
set have;
length newvar $ 10;
keep newvar;
do i=1 to length(var) while(scan(var,i,'|') ne '' );
newvar=scan(var,i,'|');
output;
end;
run;
proc print data=want;
run;
N/A
Posts: 0

Re: Create dataset uing scan function

Thanks Patrick,

I was missing output statement in the code I wrote Smiley Sad

I am new to SAS,trying to practice it but not able to find much exercises for trying writing new codes.

Regards,
Hema Tandon
Super Contributor
Super Contributor
Posts: 3,174

Re: Create dataset uing scan function

Suggested Internet search:

sas programming exercises


Also, you will find code samples here:

http://support.sas.com/documentation/onlinedoc/code.samples.html


Scott Barry
SBBWorks, Inc.
Ask a Question
Discussion stats
  • 3 replies
  • 127 views
  • 0 likes
  • 3 in conversation