BookmarkSubscribeRSS Feed
rohitkrishna
Calcite | Level 5

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

 

6 REPLIES 6
Ksharp
Super User

Try 

PUT @ 1 'H'
@ 2 BUSDATE
@ 10 Count Z8.;

rohitkrishna
Calcite | Level 5
Hi Ksharp,
Thanks for the quick response
it's working fine but may I know what is the exact thing has happening above code please kindly explain in details
Thanks & regards
rohit
rohitkrishna
Calcite | Level 5
Hi Ksharp,
why i asked the detail bez the previous sas code we didn't mention any year cutoff option=1950 that time it works fine with PUT @ 1 'H'
@ 2 BUSDATE
@ 9 Count Z8.;
above lengths no why it suddenly got 00 instead of date kindly explain it, please
thanks & regards
rohit

rohitkrishna
Calcite | Level 5
Hi Team
could anyone please explain above issue it's very helpfull
Thanks & Regards
Rohit
Kurt_Bremser
Super User

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.

Tom
Super User Tom
Super User

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?

 

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 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 491 views
  • 0 likes
  • 4 in conversation