Hi All,
Running SAS 9.4M5.
I am looking to clean up a list of potential variable names and as a result I decided to create a custom function. The problem is, even though I have explicitly set the length (excessively large at 500) of the resulting variable, I still max out at 20 characters and some of the data is being truncated. I have tested the PRXCHANGE syntax in a stand alone datastep and it works as desired, however when I copy the exact syntax into FCMP the truncation occurs.
The following is a subset list of potential variable names:
DATA HAVE;
INFILE DATALINES DLM=",";
INPUT BUFFER : $200.;
DATALINES;
Policy Number
Vehicle Sequence Number
Vehicle Suffix
Vehicle Seqno - Financials
Status
;
RUN;
The Proc FCMP step:
PROC FCMP OUTLIB=WORK.FUNCTIONS.BUSREQS;
LENGTH NEW_NAME $ 500;
FUNCTION CLEANCOLUMNNAMES(OLD_NAME $) $ 500;
NEW_NAME = PRXCHANGE('s/[^a-z A-Z 0-9_]/ /',-1,TRIM(LEFT(OLD_NAME)));
RETURN (NEW_NAME);
ENDSUB;
RUN;
OPTIONS CMPLIB = (WORK.FUNCTIONS);
Datastep using the newly created variable:
DATA WANT;
SET HAVE;
LENGTH TEST $ 500;
TEST = CLEANCOLUMNNAMES(BUFFER);
RUN;
Results showing the truncated results:
Any assistance would be greatly appreciated.
Regards,
Scott
Include your LENGTH statement in FUNCTION .
PROC FCMP OUTLIB=WORK.FUNCTIONS.BUSREQS;
FUNCTION CLEANCOLUMNNAMES(OLD_NAME $) $ 500;
LENGTH NEW_NAME $ 500; /*<-- Here*/
NEW_NAME = PRXCHANGE('s/[^a-z A-Z 0-9_]/ /',-1,TRIM(LEFT(OLD_NAME)));
RETURN (NEW_NAME);
ENDSUB;
RUN;
Include your LENGTH statement in FUNCTION .
PROC FCMP OUTLIB=WORK.FUNCTIONS.BUSREQS;
FUNCTION CLEANCOLUMNNAMES(OLD_NAME $) $ 500;
LENGTH NEW_NAME $ 500; /*<-- Here*/
NEW_NAME = PRXCHANGE('s/[^a-z A-Z 0-9_]/ /',-1,TRIM(LEFT(OLD_NAME)));
RETURN (NEW_NAME);
ENDSUB;
RUN;
Thank you @Ksharp . I will give this a shot tomorrow.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.