Hi Team,
I am facing one challenge in one of the sas code, please find the below code and the main issue is while printing the current business date, the date part has shown 00 instead of today's date kindly check and give some suggestions for that
input data:
--------------------------------------------------------------------------------------
H202001060000010
-----------------------------------------------------------------------
and the sas code
----------------------------------------------------------------------------
Busdate = &Busdatc ;
FILE LSFOHEAD; /* Header Record */
PUT @ 1 'H'
@ 2 BUSDATE
@ 9 Count Z8.;
End;
the output has
and moreover, for the global macro, it prints properly in spool
SYMBOLGEN: Macro variable BUSDATC resolves to 20200106
--------------------------------------------------------------------------
H202001000000010
------------------------------------------------------------------------
above highlighted one has a faulty date instead of 06 it shows 00 kind;ly suggest some solutions for that
Thanks & regards
Rohit
Try
PUT @ 1 'H'
@ 2 BUSDATE
@ 10 Count Z8.;
When you have a length of X and start to put at position Y, the next item must start at position Y + X. In your case, position 2 + length 8 results in next position 10.
If in doubt, use your fingers (I often do that, too, when I seem to be stuck!), or draw a ruler and count off the positions.
How is the variable BUSDATE defined?
Is it a character string? If so are all of the values exactly the same length?
Is it a numeric variable? Does it contain date values? If so what format is attached to the variable?
Or does it just contain numbers like 20,200,106 that might look to humans like a date if printed without the commas?
Your problem is with the @ pointer controls.
You wanted this layout:
----+----0----+-
H202001060000010
^^ ^
|| |
|| +-> 7 digit number with leading zeros
|=-> 8 digit date string in YYYYMMDD
+-> 1 Character code
By starting the last field in column 9 instead of 10 you have overwritten the last character of the date representation. You also wrote 8 digits for the COUNT field instead of the 7 that your pattern shows. Which length is correct?
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 16. 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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: