Hello
I want to ask a question about creating a dat set by data entry.
I want to understand please why it is written $12 near fname and $9 near class and near lname only $ (without number).
I would like to udnerstand if I create this data set by myself how to know which $w. should I write.
thanks
data Have;
input fname : $12. lname $ class : $9.;
datalines;
Jon Smith Math
John Smith Math
Johnny Smith Math
James Smith Math
Will Miller Chemistry
Willy Miller Chemistry
Willie Miller Chemistry
Bonny Davis Gym
Milly Wilson Biology
;
$w. is the default character informat (w being the width used for this particular variable). Since no separate LENGTH statement is used, the data step compiler will use the width of the informat as a length for that variable.
$ on its own means "just character", and if no explicit length was specified (see above), the data step compiler will define the variable with the default length of 8.
Which width you use for an informat (or if you can go with the default) has to be defined by what you know about the input data.
I am trying to understand how to build such data set by myself.
I see with my eyes that for var fname the max length is 6 (Johnny),
for var lname max length is 6 too (Miller),
for var class max length is 9 (Chemistry)
My question is why the person who wrote this code choose to write
fname : $12. lname $ class : $9.
fname is max length of 6 so whu did he write 9?
and so on..
Maybe there were other factors that determined the lengths.
E.g. variable lengths in an existing dataset that would be combined with this new data.
Or a data catalog for the project that defined these columns with these attributes.
@Ronein wrote:
I am trying to understand how to build such data set by myself.
I see with my eyes that for var fname the max length is 6 (Johnny),
for var lname max length is 6 too (Miller),
for var class max length is 9 (Chemistry)
My question is why the person who wrote this code choose to write
fname : $12. lname $ class : $9.fname is max length of 6 so whu did he write 9?
and so on..
Or you are only seeing part of the data as an example and there are values longer than shown.
Personally I would suspect 12 is too short for most person name fields (I routinely run into last names in the 20+ character range and first names longer than 12)
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.