BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Mike_Davis
Fluorite | Level 6

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;

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

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

9 REPLIES 9
LinusH
Tourmaline | Level 20

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
mkeintz
PROC Star

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.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
art297
Opal | Level 21

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;

eotarod03_nni_com
Calcite | Level 5

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

art297
Opal | Level 21

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

mkeintz
PROC Star

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

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Mike_Davis
Fluorite | Level 6

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

Linlin
Lapis Lazuli | Level 10

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
Mike_Davis
Fluorite | Level 6

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 9 replies
  • 1166 views
  • 6 likes
  • 6 in conversation