data want; set have; if lengthn(comrpess(name,".","d"))=0 then name_derived=compress(name,".","kd"); run;
Add the dot in. Is it that you want a numeric value? If so:
data have; a="123"; output; a="1.45"; output; a="XYZ"; output; run; data want; set have; if lengthn(compress(a,".","d"))=0 then b=input(a,best.); run;
Something like:
data want; set have; if lengthn(comrpess(name," ","d"))=0 then name_derived=compress(name," ","kd"); run;
Not tested as you have not provided test data in the form of a datastep (and not here to type in test data!).
What this does is check the length when numbers are removed, if there is nothing but numbers, then keep only them. Compress is described in the docs:
http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000212246.htm
As already requested, POST EXAMPLE DATA IN A DATA STEP!!
data want; set have; if lengthn(comrpess(name,".","d"))=0 then name_derived=compress(name,".","kd"); run;
Add the dot in. Is it that you want a numeric value? If so:
data have; a="123"; output; a="1.45"; output; a="XYZ"; output; run; data want; set have; if lengthn(compress(a,".","d"))=0 then b=input(a,best.); run;
The give code will drop alphabets and spaces, only contains numeric(float datatype as well)
data want(drop = YourVariable);
set have;
NewVariable = input(compress(YourVariable,'1234567890.','k'),best12.);
run;
Unfortunately that doesn't match the required output (otherwise it would have been mentioned):
data have; input yourvariable $; datalines; negative 45 1E positive 24 ; run; data want (drop=yourvariable); set have; newvariable=input(compress(yourvariable,'1234567890.','k'),best12.); run;
See row 3.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.