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

I have character variable and for sorting purpose i need to create a numeric variable:

 

I have plade as character and need something like pladen for numeric sorting. and the issue is the plade is if plade is not in order as mentioned then somehow it scan and look and the last text and create numeric values

plade
pa101
pa102
pa103
pa104
pa105
pa106
pa107
pa108
pa109
pa110
pa111
pa112
pa113
pa114
pa101f
pa102f
pa103f
pa104f
pa105f
pa106f
pa107f
pa108f
pa109f
pa110f
pa111f
pa112f
pa113f
pa114f
pa101e
pa102e
pa103e
pa104e
pa105e
pa106e
pa107e
pa108e
pa109e
pa110e
pa111e
pa112e
pa113e
pa114e

 

i need numeric variable like the below - any help

 

plade pladen
pa101 1
pa102 2
pa103 3
pa104 4
pa105 5
pa106 6
pa107 7
pa108 8
pa109 9
pa110 10
pa111 11
pa112 12
pa113 13
pa114 14
pa101f 101
pa102f 102
pa103f 103
pa104f 104
pa105f 105
pa106f 106
pa107f 107
pa108f 108
pa109f 109
pa110f 110
pa111f 111
pa112f 112
pa113f 113
pa114f 114
pa101e 201
pa102e 202
pa103e 203
pa104e 204
pa105e 205
pa106e 206
pa107e 207
pa108e 208
pa109e 209
pa110e 210
pa111e 211
pa112e 212
pa113e 213
pa114e 214
1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Try this:

data want;
set have;
pladen = input(substr(plade,3,3),3.);
select (substr(plade,6,1));
  when ('f'); /* do nothing */
  when (' ') pladen = pladen - 100;
  when ('e') pladen = pladen + 100;
end;
run;

View solution in original post

5 REPLIES 5
noda6003
Quartz | Level 8

create a numeric variable if pa101 than 1 and if pas101f than 201 and pa101f than 101 etc. 

ed_sas_member
Meteorite | Level 14

Like this ?

data have2;
	set have;
	i=substr(plade,6,1);
	j=substr(plade,4,2);

data have3 (drop= i j count);
	set have2;
	by i notsorted;
	retain count -1;
	if first.i then count+1;
	pladen = count*100 + j;
run;
noda6003
Quartz | Level 8

also creates 301,401 and 601 as numbers

Kurt_Bremser
Super User

Try this:

data want;
set have;
pladen = input(substr(plade,3,3),3.);
select (substr(plade,6,1));
  when ('f'); /* do nothing */
  when (' ') pladen = pladen - 100;
  when ('e') pladen = pladen + 100;
end;
run;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

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