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;
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?
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?
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.