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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.