DATA Step, Macro, Functions and more

working character and DATE

Reply
Occasional Contributor HM3
Occasional Contributor
Posts: 9

working character and DATE

data test;
a=2;
b=2;
proc print data=test;
run;
this will give me a=2 b=2.
Now I want to do same for
a=m;
b=a;

and want to get the output a=m b=m.

Can the same done with dates?

how to declare the same?
data test;
a=12/10/2009 --> how to extract the weekday from a?
Pl help.
partha
Super Contributor
Super Contributor
Posts: 3,174

Re: working character and DATE

The SAS language has date and datetime functions. Check the DOC - suggested reading link provided below.

Scott Barry
SBBWorks, Inc.

SAS Language Reference: Concepts, About SAS Date, Time, and Datetime Values
http://support.sas.com/documentation/cdl/en/lrcon/61722/HTML/default/a002200738.htm
Contributor
Posts: 34

Re: working character and DATE

> data test;
> a=2;
> b=2;
> proc print data=test;
> run;
> this will give me a=2 b=2.
> Now I want to do same for
> a=m;
> b=a;
>
> and want to get the output a=m b=m.

You have to use quatition mark inorder to assign value to variable.

a='m';
b=a;

> how to declare the same?
> data test;
> a=12/10/2009 --> how to extract the weekday from a?
> Pl help.
> partha

You can use INPUT function like below.

A=INPUT('12/10/2009',MMDDYY10.);
Occasional Contributor HM3
Occasional Contributor
Posts: 9

Re: working character and DATE

Thanks.
Super Contributor
Posts: 673

Re: working character and DATE

Partha,
Are you looking for this:

proc format;
value whatday 1='Sunday'
2='Monday'
3='Tuesday'
4='Wednesday'
5='Thursday'
6='Friday'
7='Saturday';

run;

data test;
a='12/18/2009';
b=input(a,mmddyy10.);
format b mmddyy10.;
c=weekday(b);
format c whatday.;
run;
Super Contributor
Super Contributor
Posts: 3,174

Re: working character and DATE

If interested, consider a more standard approach using the SAS-supplied DOWNAME format to get the weekday name from a SAS DATE type variable.

Scott Barry
SBBWorks, Inc.
Valued Guide
Posts: 2,177

Re: working character and DATE

HM3
are you talking "constants"?
a=2
assigns a constant to variable A.
"25dec2009"d
is a date constant
Ask a Question
Discussion stats
  • 6 replies
  • 190 views
  • 0 likes
  • 5 in conversation