BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sulafa
Obsidian | Level 7

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

 
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
72
73 DATA WORK.Contact_MS ;
74 LENGTH SocSecNum $11
75 FirstInit $2
76 MiddleInit $2
77 LastInit $2
78 CityState $35
79 ZipCD $5;
80 SET .... (RENAME=(SocSecNum= SSN));
81
82
83 FirstInit = COMPRESS(FirstInit,'.');
84 MiddleInit = COMPRESS(MiddleInit,'.');
85 LastInit = COMPRESS(LastInit,'.')
86 Inits = CATS(FirstInit,MiddleInit,LastInit);
_____
22
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, ;, <, <=, <>, =, >, ><, >=, AND, EQ, GE, GT,
IN, LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR, ^=, |, ||, ~=.
 
87 City = SCAN(CityState, 1, ' ,');
88 StateCd = SCAN(CityState, 2, ' ,');
89 KEEP SSN
90 Inits
91 City
92 StateCd
93 ZipCd;
94
95 RUN;
 
NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
85:22 86:22
NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
1:1
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set ... may be incomplete. When this step was stopped there were 0 observations and 5 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
 
 
96
97 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;

THANK YOU!

sulafa
1 ACCEPTED SOLUTION

Accepted Solutions
sustagens
Pyrite | Level 9

End this line with a semicolon

LastInit = COMPRESS(LastInit,'.')

View solution in original post

11 REPLIES 11
sulafa
Obsidian | Level 7

I am attaching also what is the data set looks like:-

sulafa_0-1604451991493.png

 

sulafa
PaigeMiller
Diamond | Level 26

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".

--
Paige Miller
sulafa
Obsidian | Level 7
That makes sense, I am going to do that, thank you!
sulafa
andreas_lds
Jade | Level 19

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!

sulafa
Obsidian | Level 7
That Makes sense Andreas, I am going to do that, thank you so much!
sulafa
sulafa
Obsidian | Level 7


here is my Data Step:-
DATA WORK.Contact_MS ;
LENGTH SocSecNum $11
FirstInit $2
MiddleInit $2
LastInit $2
CityState $35
ZipCD $5;
SET HypImpt.MS_Citizens (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;







sulafa
sulafa
Obsidian | Level 7
here is the log:-

1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
72
73 DATA WORK.Contact_MS ;
74 LENGTH SocSecNum $11
75 FirstInit $2
76 MiddleInit $2
77 LastInit $2
78 CityState $35
79 ZipCD $5;
80 SET HypImpt.MS_Citizens (RENAME=(SocSecNum= SSN));
81
82
83 FirstInit = COMPRESS(FirstInit,'.');
84 MiddleInit = COMPRESS(MiddleInit,'.');
85 LastInit = COMPRESS(LastInit,'.')
86 Inits = CATS(FirstInit,MiddleInit,LastInit);
_____
22
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, ;, <, <=, <>, =, >, ><, >=, AND, EQ, GE, GT,
IN, LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR, ^=, |, ||, ~=.

87 City = SCAN(CityState, 1, ' ,');
88 StateCd = SCAN(CityState, 2, ' ,');
89 KEEP SSN
90 Inits
91 City
92 StateCd
93 ZipCd;
94
95 RUN;

NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
85:22 86:22
NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
1:1
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.CONTACT_MS may be incomplete. When this step was stopped there were 0 observations and 5 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds


96
97 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
109
sulafa
PaigeMiller
Diamond | Level 26

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)

--
Paige Miller
sulafa
Obsidian | Level 7
Hello PaigeMiller,
thank you so much for follow up with me, and I am sorry I missed your message, I tried to do as instructed by failed, but the problem solved, thank you again.
best,
Sulafa
sulafa
sustagens
Pyrite | Level 9

End this line with a semicolon

LastInit = COMPRESS(LastInit,'.')
sulafa
Obsidian | Level 7
Hello Sustagens,
thank you so much, that works!
sulafa

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 11 replies
  • 1450 views
  • 2 likes
  • 4 in conversation