Hello
Below code was running on host SAS
data long; length name $ 8; format name $8.; infile datalines dsd; input name; datalines4; aaaaaaaa bbbbbbbb cccccccc dddddddd ;;;; run; data short; length name $ 4; format name $4.; infile datalines dsd; input name; datalines4; eeee ffff gggg hhhh ;;;; run; data longfirst; set long short; run;
when this code was running on SAS Host
dataset longfirst has variable name with length 8 and format $8.
Name
aaaaaaaa
bbbbbbbb
cccccccc
dddddddd
eeee
ffff
gggg
hhhh
But when I am running the same code on SAS 9.4 on windows
dataset longfirst has output with variable name has length 8 and format $4.
name
aaaa
bbbb
cccc
dddd
eeee
ffff
gggg
hhhh
My question is when i am running the same code on windows why variable name has format $4. due to which output data is not showing correct ?
@shubham1 wrote:
Hello
Below code was running on host SAS
data long; length name $ 8; format name $8.; infile datalines dsd; input name; datalines4; aaaaaaaa bbbbbbbb cccccccc dddddddd ;;;; run; data short; length name $ 4; format name $4.; infile datalines dsd; input name; datalines4; eeee ffff gggg hhhh ;;;; run; data longfirst; set long short; run;
when this code was running on SAS Host
dataset longfirst has variable name with length 8 and format $8.
Name
aaaaaaaa
bbbbbbbb
cccccccc
dddddddd
eeee
ffff
gggg
hhhh
But when I am running the same code on SAS 9.4 on windows
dataset longfirst has output with variable name has length 8 and format $4.
name
aaaa
bbbb
cccc
dddd
eeee
ffff
gggg
hhhh
My question is when i am running the same code on windows why variable name has format $4. due to which output data is not showing correct ?
Show the exact code as run copied from the log with any messages. You describe for your Windows run what would happen with :
data longfirst; set short long; run;
I ran your code on a Windows stand alone SAS install and Name is length 8 with format $8.
The result you explain is not possible. Please check what you have done.
When you are setting multiple datasets together like that the first place SAS sees the variable will determine the variables type (and length). The first place where there is a non-empty format attached will determine what format is attached.
So you must have done this:
data long;
length x $8 ;
run;
data short;
length x $4 ;
format x $4. ;
run;
data long_short ;
set long short ;
run;
Instead of what you described.
This is why I recommend to NOT attach $ format to any character variables. And rant at posters that use FORMAT statement as if it was intended to DEFINE the variables. The FORMAT statement is for attaching a default format to use when display a variable. It will only define the variable as a side effect when it is the first place that the compiler sees the variable referenced.
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!
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.