sequencing character numbers in data step

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 11
Accepted Solution

sequencing character numbers in data step

Hello,

I'm trying to get all of the codes starting from 394.0-397.1 in the data step. these numbers in a character format.

data code2;

set code;

where code in ('394.0' -'397.1');

run;

Thanks for your help in advance.


Accepted Solutions
Solution
‎07-16-2015 12:42 PM
Contributor
Posts: 74

Re: sequencing character numbers in data step

data code2;

set code;

coden = input(code, best.);

where 394.0 le coden le 397.1;

run;

View solution in original post


All Replies
Solution
‎07-16-2015 12:42 PM
Contributor
Posts: 74

Re: sequencing character numbers in data step

data code2;

set code;

coden = input(code, best.);

where 394.0 le coden le 397.1;

run;

Frequent Contributor
Posts: 130

Re: sequencing character numbers in data step

You can't do a WHERE statement on a new, created variable in the same data step, as the where statement happens before the data enters the PDV.  Try the following instead:

data have;

input Code $;

datalines;

394.0

393.0

395.5

397.1

399.2

;

run;

data want;

set have;

Code_n=input(put(Code,$6.),5.1);

If 394<=Code_n<=397.1 then output;

run;

Contributor
Posts: 74

Re: sequencing character numbers in data step

Ok, thanks.

Valued Guide
Posts: 858

Re: sequencing character numbers in data step

SAS will still read the characters as numbers if you are using number operators and SAS can translate it correctly.  You do not need to change the format:

data have;

input code$;

cards;

393

394.0

394.1

397.0

397.1

397.4

398

;

run;

data want;

set have;

where '394'<=Code<='397.1';

run;

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 225 views
  • 4 likes
  • 4 in conversation