Hello SAS Communities,
I am working on a code but have some errors, below what I need to do:-
1. to concatenate three variables ( FirstInit, MiddleInit, LastInit) into one variable named Inits.
2. Extract the "City" from Text Strings(CityState).
3. Extract the "StateCd" from Text Strings(CityState).
My Code looks like this
DATA ..... ;
LENGTH SocSecNum $11
FirstInit $2
MiddleInit $2
LastInit $2
CityState $35
ZipCD $5;
SET .... (RENAME=(SocSecNum= SSN));
FirstInit = COMPRESS(FirstInit,'.');
MiddleInit = COMPRESS(MiddleInit,'.');
LastInit = COMPRESS(LastInit,'.')
Inits = CATS(FirstInit,MiddleInit,LastInit);
City = SCAN(CityState, 1, ' ,');
StateCd = SCAN(CityState, 2, ' ,');
KEEP SSN
Inits
City
StateCd
ZipCd;
RUN;
Here what the log looks like
THANK YOU!
I am attaching also what is the data set looks like:-
Many people will not download Microsoft Office documents because they are a security threat. Post your log by copying it as text from the LOG window (not from your MS Office document) and pasting it into the window that appears here when you click on the </> icon. Do not skip this step. Do not post LOG contents any other way.
Please go back and edit your original message and provide a meaningful title that describes your problem. A title of "Programming Question" could apply to almost every message here and is not informative. This helps everyone out as people may search for their problem and won't find it if your title says "Programming Question".
Please post data as a data step using datalines, screenshots are hardly helpful. Then you must explain what the problem is, if you get any errors, post the complete log using the "insert code" button.
Task 1: using cats alone should be sufficient, i don't see the need for compress.
Task 2+3: Use "," as third parameter for scan, no blank inside the quotes!
Would you please provide the log as I instructed, to preserve the formatting and make it easier to read? (And thank you for the subject line modification)
End this line with a semicolon
LastInit = COMPRESS(LastInit,'.')
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.