BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jammy
Calcite | Level 5


Hi all,

I need help with the following:

I have a 2 variables in a dataset

n= number

label = string e.g. X!3.479!3.49902!3.43968!3.49919!3.5432!3.69513!3.52109!3.53714!

What I need to do is - retrieve the 'n' th value (seperated by "!").

For example:

n= 2

value= 3.49902

Im guessing I need to use a scan?

Many thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

jammy,

Yes, you'll need SCAN.  However, SCAN alone will create VALUE as a character variable:

value = scan(string, n, '!');

If you want VALUE as a numeric variable, you'll have to apply the INPUT function to the result returned by the SCAN function:

value = input( scan(string, n, '!'), 8.);

It won't hurt to use a length of 8 in the INPUT function when the incoming string contains fewer than 8 characters.  Good luck.

View solution in original post

4 REPLIES 4
LinusH
Tourmaline | Level 20

Yes

Data never sleeps
jammy
Calcite | Level 5


My bad..... I was trying to make it more complicated than it is!

Cheers

Astounding
PROC Star

jammy,

Yes, you'll need SCAN.  However, SCAN alone will create VALUE as a character variable:

value = scan(string, n, '!');

If you want VALUE as a numeric variable, you'll have to apply the INPUT function to the result returned by the SCAN function:

value = input( scan(string, n, '!'), 8.);

It won't hurt to use a length of 8 in the INPUT function when the incoming string contains fewer than 8 characters.  Good luck.

Jagadishkatam
Amethyst | Level 16

Also if you want to know the different nth values, try the below code

data have;

    string="X!3.479!3.49902!3.43968!3.49919!3.5432!3.69513!3.52109!3.53714!";

do i = 1 to 10;

    new=scan(string,i,'!');

    output;

end;

run;

Thanks,

Jag

Thanks,
Jag

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
  • 4 replies
  • 992 views
  • 0 likes
  • 4 in conversation