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

 

code:

data scoredata2;
set scoredata0;
gender_ac = gender||'/'||gender_code; /*auto*/
gender_char = put (gender_code, 8.); /*put*/
run;

 

in set scoredata0:

gender=1 char

gender_code=8 numeric

how the length  of newvar calculated here.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Why not just TELL the compiler what length your WANT to use for the new variables instead of forcing it to guess?

data scoredata2;
  set scoredata0;
  length gender_ac $21 gender_char $8;
  gender_ac = gender||'/'||gender_code; /*auto*/
  gender_char = put (gender_code, 8.); /*put*/
run;

SAS will use the BEST12 format when you let it auto convert a number into a string.  So the values of GENDER_AC will be the length of GENDER (is that 1 byte? 6 bytes? Something else) plus 1 plus 12.  Whether SAS is smart enough to figure that number out or whether it just use 200 you would have to run it and see.  For the second step the values will all be length of 8 bytes.  I would assume the compiler could figure that out and define gender_char as length $8 since that length is known at compile time based on the width of the format used in the PUT() function call.

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

Why not just TELL the compiler what length your WANT to use for the new variables instead of forcing it to guess?

data scoredata2;
  set scoredata0;
  length gender_ac $21 gender_char $8;
  gender_ac = gender||'/'||gender_code; /*auto*/
  gender_char = put (gender_code, 8.); /*put*/
run;

SAS will use the BEST12 format when you let it auto convert a number into a string.  So the values of GENDER_AC will be the length of GENDER (is that 1 byte? 6 bytes? Something else) plus 1 plus 12.  Whether SAS is smart enough to figure that number out or whether it just use 200 you would have to run it and see.  For the second step the values will all be length of 8 bytes.  I would assume the compiler could figure that out and define gender_char as length $8 since that length is known at compile time based on the width of the format used in the PUT() function call.

rajeshm
Quartz | Level 8
length of the variable is 14 only.
I read the best12. but forget while applying that logic here.
Thanks a lot for letting me know quickly.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 669 views
  • 1 like
  • 2 in conversation