SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
qinghe
Calcite | Level 5

Hi, 

 

I want to know how to solve the error " Invalid value for width specified" in the following program:

data A;
input record_id name $ mark;
cards;
1100111 A 99
1100112 B 78
2100111 C 60
2100100 D 78
2100112 E 91
3100111 F 40
3011112 G 36
;

data B (rename=(record_id=start));
retain fmtname "select" label "A";
set test;
where mod(record_id,10) in (0, 1);
run;

proc format cntlin=B;
run;

proc sql;
create table A_selected as
select * from test
where put(record_id, select.)="A";
quit;

 

I can get the correct output, but with error messages.

 

Thank you in advance.

 

Qinghe

3 REPLIES 3
qinghe
Calcite | Level 5

Hi, 

 

I am sorry that there is a typo in the program:

 

"select * from test" should be "select * from A"

 

Regards,

Qinghe

FreelanceReinh
Jade | Level 19

Hello @qinghe,

 

To avoid the error message, specify a sufficient default length (such as 7 characters if this is the maximum number of digits in the RECORD_ID values) for your format:

retain fmtname "select" label "A" default 7;

Without this specification the default length is 1, which is insufficient to write the RECORD_IDs which are not classified as "A", hence the error message.

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 459 views
  • 0 likes
  • 2 in conversation