DATA Step, Macro, Functions and more

problem with sas code

Accepted Solution Solved
Reply
Contributor
Posts: 38
Accepted Solution

problem with sas code

Hello everyone,

I am facing problem with entering dates manually. Isn't there any loop kind of procedure so that dates get entered automatically.

for eg: I am having a dataset of 21 observations, i want to enter different date infront of each of them. Will i have to enter them manually using cards statement or there is an automated procedure?


Accepted Solutions
Solution
‎07-02-2017 12:11 PM
Trusted Advisor
Posts: 1,137

Re: problem with sas code

Posted in reply to atulsingh

Consider that you have the dataset with name have and you need to create a variable date in want. so you could follow as below

 

the date will create dates from 01jul2017 to 21jul2017 depending on the number of rows

 

data want;
do until(date ne .);
set have;
date=intnx('day','01jul2017'd,_n_);
end;
format date date9.;
run;
Thanks,
Jag

View solution in original post


All Replies
Super User
Super User
Posts: 7,076

Re: problem with sas code

Posted in reply to atulsingh

What dates do you want? What do you mean by "entered"?  Where do you want it "entered"?  How can a date be in front of an observation?

Please provide a litte more detail. For example you could provide a data step to create a copy of your 21 observations and explain what dates you need added.

Contributor
Posts: 38

Re: problem with sas code

I want dates from 1st july 2017 to 21st july 2017 infront of every observations. How to do it?


sas.png
Contributor
Posts: 38

Re: problem with sas code

Posted in reply to atulsingh

Please anyone reply fast. Refer the above attachment for dataset.

Solution
‎07-02-2017 12:11 PM
Trusted Advisor
Posts: 1,137

Re: problem with sas code

Posted in reply to atulsingh

Consider that you have the dataset with name have and you need to create a variable date in want. so you could follow as below

 

the date will create dates from 01jul2017 to 21jul2017 depending on the number of rows

 

data want;
do until(date ne .);
set have;
date=intnx('day','01jul2017'd,_n_);
end;
format date date9.;
run;
Thanks,
Jag
Valued Guide
Posts: 765

Re: problem with sas code

Posted in reply to Jagadishkatam

Hi, curious ... why use a loop in this example ...

 

data want;
do until(date ne .);
set have;
date=intnx('day','01jul2017'd,_n_);
end;
format date date9.;
run;

 

Why not just ...

 

data want;
set have;
date=intnx('day','01jul2017'd,_n_);
format date date9.;
run;

Super User
Posts: 19,869

Re: problem with sas code

Posted in reply to atulsingh

You showed us what you have. What do you need as output - that's unclear.

 


atulsingh wrote:

Hello everyone,

I am facing problem with entering dates manually. Isn't there any loop kind of procedure so that dates get entered automatically.

for eg: I am having a dataset of 21 observations, i want to enter different date infront of each of them. Will i have to enter them manually using cards statement or there is an automated procedure?


 

☑ This topic is solved.

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

Discussion stats
  • 6 replies
  • 224 views
  • 0 likes
  • 5 in conversation