turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- General Programming
- /
- Selection of variables using x1-x5, but with strin...

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

12-01-2017 06:08 AM

hi! Ive ran into a problem where i need to create a range of values, contained in strings. The data given is on the format

X-H-237 to X-H-240 (in reality its a lot more values, but for simplicity lets settle with 237-240).

Is there a function or similar that can handle this problem?

Below is a script showing what i want to do.

data Matrix(drop= i);

array A(*) A1-A7;

do i=1 to 7;

A(i)=rand('Uniform');

end;

format B $10.;

input B $;

datalines;

X-H-237

X-H-238

X-H-239

X-H-240

;

run;

data test;

/*State 1-5 Rk-states, 6=Delinquent 7=default */

set Matrix;

if B in "X-H-237"--"X-H-240" then put A1;

if B in "X-H-237"-"X-H-240" then put A2;

run;

Accepted Solutions

Solution

12-01-2017
06:38 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Shawnty

12-01-2017 06:27 AM

There really is no need to code all in mixed case, its very hard to read. Now, you can simply change you code to number and use that, thus:

data matrix(drop= i); array a(*) a1-a7; do i=1 to 7; a(i)=rand('uniform'); end; format b $10.; input b $; datalines; X-H-237 X-H-238 X-H-239 X-H-240 ; run; data test; set matrix; if 237 <= input(scan(b,3,"-"),best.) <= 240 then put a1; run;

(you will note the use of the code window to preserve indenting). With that you can do numeric ranges, although I do not know what the second datastep is meant to acheive?

All Replies

Solution

12-01-2017
06:38 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Shawnty

12-01-2017 06:27 AM

There really is no need to code all in mixed case, its very hard to read. Now, you can simply change you code to number and use that, thus:

data matrix(drop= i); array a(*) a1-a7; do i=1 to 7; a(i)=rand('uniform'); end; format b $10.; input b $; datalines; X-H-237 X-H-238 X-H-239 X-H-240 ; run; data test; set matrix; if 237 <= input(scan(b,3,"-"),best.) <= 240 then put a1; run;

(you will note the use of the code window to preserve indenting). With that you can do numeric ranges, although I do not know what the second datastep is meant to acheive?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

12-01-2017 06:38 AM

Hi RW9, Exactly what i was looking for. Thank you!

Second datastep was just created to illustrate the if statement. What happends in it was irrelevant for the question so i left it out.

Second datastep was just created to illustrate the if statement. What happends in it was irrelevant for the question so i left it out.