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 |
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;
What is the logic here?
create a numeric variable if pa101 than 1 and if pas101f than 201 and pa101f than 101 etc.
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;
also creates 301,401 and 601 as numbers
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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.