BookmarkSubscribeRSS Feed
HeatherNewton
Quartz | Level 8
data lemon;
  input accountno1 accountno2 accountno3 ;
datalines;
1234567890   123456789012    12345678901234
run;


data test;
set lemon;
result1=compress(substr(accountno1,1,8)||put((input(substr(accountno1,9,1),1.)-1),5.)||substr(accountno1,10,7)||put((input(substr(accountno1,17,1),1.)+1),5.)||substr(accountno1,18,2)," ");
result2=compress(substr(accountno2,1,8)||put((input(substr(accountno1,9,1),1.)-1),5.)||substr(accountno1,10,7)||put((input(substr(accountno1,17,1),1.)+1),5.)||substr(accountno1,18,2)," ");
result3=compress(substr(accountno3,1,8)||put((input(substr(accountno1,9,1),1.)-1),5.)||substr(accountno1,10,7)||put((input(substr(accountno1,17,1),1.)+1),5.)||substr(accountno1,18,2)," ");
output out=test;
run;

proc print data=test;
run;
GETTING BELOW ERRORS, PLEASE KINDLY TAKE A LOOK FOR ME, THANKS.
 
78 result1=compress(substr(accountno1,1,8)||put((input(substr(accountno1,9,1),1.)-1),5.)||substr(accountno1,10,7)||put((inpu
78 ! t(substr(accountno1,17,1),1.)+1),5.)||substr(accountno1,18,2)," ");
79 result2=compress(substr(accountno2,1,8)||put((input(substr(accountno1,9,1),1.)-1),5.)||substr(accountno1,10,7)||put((inpu
79 ! t(substr(accountno1,17,1),1.)+1),5.)||substr(accountno1,18,2)," ");
80 result3=compress(substr(accountno3,1,8)||put((input(substr(accountno1,9,1),1.)-1),5.)||substr(accountno1,10,7)||put((inpu
80 ! t(substr(accountno1,17,1),1.)+1),5.)||substr(accountno1,18,2)," ");
81 output out=test;
_
79
___
455
ERROR 79-322: Expecting a RC.
 
ERROR 455-185: Data set was not specified on the DATA statement.
 
82 run;
7 REPLIES 7
japelin
Rhodochrosite | Level 12

The out= is not required for the output statement in the data step.

output test;
japelin
Rhodochrosite | Level 12

Again, if your question has been answered, please mark the answer as "Accepted Solution" for the benefit of later viewers.

 

Please review the following guidelines.
https://communities.sas.com/t5/Getting-Started/Community-etiquette-The-do-s-and-don-ts-of-the-SAS-Su...

 

 

ballardw
Super User

I get curious about who/why/how someone managed to screw up values in the middle of an account number that need to be adjusted that way.

 

Post your log in a text box. You will see that the error:

81 output out=test;
_
79
___
455
 
would have the underscore character in two places because of two different types of errors as in this:
1    data junk;
2       set sashelp.class;
3       output out=junk;
                  -
                  79
               ---
               455
ERROR 79-322: Expecting a RC.

ERROR 455-185: Data set was not specified on the DATA statement.

4    run;
The first single underscore associated with the 79-322 error says the = sign is not expected.
The second set of 3 undescores is under the word OUT. The Output statement only takes a data set name as an option. That name must be on the DATA statement at the start of the data step. So the codes are telling you that OUT is not acceptable as the name of a data step for output. Coupled they tell you that "Out=" does not belong with OUTPUT.
 
And the OUTPUT statement is not needed in this case.
 
After you fix the OUTPUT statement problem be prepared to deal with many invalid data notes:
12   data test;
13   set lemon;
14   result1=compress(substr(accountno1,1,8)||put((input(substr(accountno1,9,1),1.)-1),5.)||substr
14 ! (accountno1,10,7)||put((input(substr(accountno1,17,1),1.)+1),5.)||substr(accountno1,18,2),"
14 ! ");
15   result2=compress(substr(accountno2,1,8)||put((input(substr(accountno1,9,1),1.)-1),5.)||substr
15 ! (accountno1,10,7)||put((input(substr(accountno1,17,1),1.)+1),5.)||substr(accountno1,18,2),"
15 ! ");
16   result3=compress(substr(accountno3,1,8)||put((input(substr(accountno1,9,1),1.)-1),5.)||substr
16 ! (accountno1,10,7)||put((input(substr(accountno1,17,1),1.)+1),5.)||substr(accountno1,18,2),"
16 ! ");
17   run;

NOTE: Numeric values have been converted to character values at the places given by:
      (Line):(Column).
      14:25    14:60    14:95    14:131   14:167   15:25    15:60    15:95    15:131   15:167
      16:25    16:60    16:95    16:131   16:167
NOTE: Invalid third argument to function SUBSTR at line 14 column 88.
NOTE: Invalid second argument to function SUBSTR at line 14 column 124.
NOTE: Invalid second argument to function SUBSTR at line 14 column 160.
NOTE: Invalid third argument to function SUBSTR at line 15 column 88.
NOTE: Invalid second argument to function SUBSTR at line 15 column 124.
NOTE: Invalid second argument to function SUBSTR at line 15 column 160.
NOTE: Invalid third argument to function SUBSTR at line 16 column 88.
NOTE: Invalid second argument to function SUBSTR at line 16 column 124.
NOTE: Invalid second argument to function SUBSTR at line 16 column 160.
accountno1=1234567890 accountno2=123456789012 accountno3=1.2345679E13 result1=1234566890.
result2=123456786890. result3=1.2345676890. _ERROR_=1 _N_=1
NOTE: Missing values were generated as a result of performing an operation on missing values.
      Each place is given by: (Number of times) at (Line):(Column).
      1 at 14:151   1 at 15:151   1 at 16:151
The way you read the account variables was a numeric values. So when you drop them into a character function, such as SUBSTR, SAS does a conversion to character from number and may not use the character string you expect. There are also some possible side effects from using the || operator to concatenate things that often result in embedded blanks where you don't expect them.

 

HeatherNewton
Quartz | Level 8

I fixed the error and it runs but still  I cannot understand what it is trying to do with all the compress input put, also the 5. does not seem to be doing anything significant here

I end up getting all three results with 10 digits 

Kurt_Bremser
Super User

We don't understand either. Using the character function SUBSTR on numeric values is simply a VERY BAD IDEA.

Are you sure that the variable is numeric in your original dataset (use PROC CONTENTS)?

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 7 replies
  • 510 views
  • 2 likes
  • 4 in conversation