Help using Base SAS procedures

SAS date value problem

Accepted Solution Solved
Reply
Regular Contributor
Posts: 222
Accepted Solution

SAS date value problem

Hello everyone,

The following SAS code, why variable bbb can't be a date value like aaa?

Thanks

Mike

%let date=Jan2011;

data test;

length xx $9;

length xx3 $11;

date=symget('date');

xx='01'||date;

xx3=strip(quote(xx));

yy="'"||xx||"'"||"d";

*yy2="'"||"Jan2011"||"'"||"d";

*yy2_2="'"||"01Jan2011"||"'"||"d";

aaa="01Jan2011"d;

bbb=xx3||'d';

yy3="01&date"d;

run;


Accepted Solutions
Solution
‎08-21-2012 10:57 AM
PROC Star
Posts: 7,467

Re: SAS date value problem

Posted in reply to Mike_Davis

Are you only trying to accomplish something like?:

%let date=Jan2011;

data test;

  format date date9.;

  date=input(catt("01",substr("&date.",1,3),substr("&date.",4)),date9.);

run;

View solution in original post


All Replies
Super User
Posts: 5,424

Re: SAS date value problem

Posted in reply to Mike_Davis

When asigning bbb, you are putting the date constant within a string.

When asigning aaa (and yy3), the d-literal is in "open code", which SAS uses during execution time to interpret the contents of the preceding string. Having the data literal within a string will prevent the SAS from interacting with it.

Data never sleeps
Trusted Advisor
Posts: 1,015

Re: SAS date value problem

Posted in reply to Mike_Davis

You are confusing date literals with character variables, just because both involve quotes. XX3 is a character variable that happens to have quotes in its value, and then you appended a D when you assigned it to BBB. Result: BBB is a character variable.


SAS only know you are specifying a date literal when the program is being interpreted, not when it is being executed (after all XX3 could just a likely had a value of "abcdef"). Therefore the quotes need to be in the actual SAS script (either explicitly or through interpreting of macro variables). SAS will not look inside the value of XX3 to see that you intended it to be a date literal.

Solution
‎08-21-2012 10:57 AM
PROC Star
Posts: 7,467

Re: SAS date value problem

Posted in reply to Mike_Davis

Are you only trying to accomplish something like?:

%let date=Jan2011;

data test;

  format date date9.;

  date=input(catt("01",substr("&date.",1,3),substr("&date.",4)),date9.);

run;

Occasional Contributor
Posts: 5

Re: SAS date value problem

Arthur,

I have 30 emails from ypou on my inbox again. How hard is it for you to exclude my name from your distribution list? I have put stop on tacking issues and still receive your responses to other individauls's question. Please take a few minutes and exclude my name before you send any replies to anyone.

Thanks

PROC Star
Posts: 7,467

Re: SAS date value problem

Posted in reply to eotarod03_nni_com

Ellaheh: I am NOT the one sending you emails.  You have full control over that in the SAS Forum settings.

Trusted Advisor
Posts: 1,015

Re: SAS date value problem

Posted in reply to eotarod03_nni_com

Perhaps you marked Art as someone you are "following"?

Regular Contributor
Posts: 222

Re: SAS date value problem

Posted in reply to eotarod03_nni_com

hi otarod03@nni.com, yu must had set receiving Email notification options and  you specify you follow with Dr.Art.

you should login to your account manager to do something.

Thanj you

Mike

Super Contributor
Posts: 1,636

Re: SAS date value problem

Posted in reply to eotarod03_nni_com

Hi,

please check the attached files and follow the three steps to change your email settings. I chose to get notified when Cynthis posts. So when I select Cynthis you should select Art. in step one, click "view all participants", in step two, click "Art", in step 3, click "stop email notification". please let me know if you need further help.


step2.pngstep1.pngstep3.png
Regular Contributor
Posts: 222

Re: SAS date value problem

Thank you Art,

base on your code,need is what I need:

%let date=Jan1986;
%let lowdate=Jan1900;
%let update=Jan2112;
data test8;
date=symget('date');
xx=cats('01',date);
need=input(xx,date9.);

lowdate=symget('lowdate');
xx2=cats('01',lowdate);
low=input(xx2,date9.);

update=symget('update');
xx3=cats('01',update);
up=input(xx3,date9.);
if 0 lt need lt 55518 then put 'year of date between 1960 and 2112';
else put 'date illegal';
run;

SAS code was updated by: Mike Davis

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 9 replies
  • 289 views
  • 6 likes
  • 6 in conversation