Desktop productivity for business analysts and programmers

How to copy the first cell to the next cells in one column?

Reply
New Contributor
Posts: 2

How to copy the first cell to the next cells in one column?

Hi:

I've just begin learning Enterprise Guide for a month.

I encountered the problem below. 

In the picture, the data is continuous, but in the Program Name column, the yellow cells are useless. Therefore, I'd copy the first program name to the next cells in same column until next "PRO" in Column of "Cycle", and do the same action continually.

I'd count the Error code for each program, example...."Program X has 2 shift, 2 open and 1 limited".

Does it has any code or method to slove this?

The only way I think is "do loop", I even don't know it is correct or not. It's really difficult for me....

 

Problem.png

Super User
Posts: 5,362

Re: How to copy the first cell to the next cells in one column?

Here's some code that will do what you are asking for.  However, the order of the columns will change:

 

data want;

set have;

if cycle='PRO' then New_Program_Name = Program_Name;

retain New_Program_Name;

drop Program_Name;

rename New_Program_Name = Program_Name;

run;

 

If the order of the columns is important, you can preserve that.  The way you would learn the most:  find the length of Program_Name.  Then insert between the DATA and SET statement:

 

length Date Time 8 Cycle $ 6 Program_Name New_Program_Name $ 6;

 

Those numbers are just examples ... you have to use whatever is in your data.

 

You can automate the process instead, but it will look a little complex.  Insert between the DATA and SET statements:

 

if 5=4 then do;

   set have (keep=date time cycle program_name);

   New_Program_Name = program_name;

end;

New Contributor
Posts: 2

Re: How to copy the first cell to the next cells in one column?

Thank you for your respond.

Sorry for late reply. I have discussed with my friend for two weeks. We still cannot solve this problem.

I follow your suggestion and put the code into the project.

We encountered the problem below. The column of "Program_Name" all disappeared.Problem.PNG

Could you please help to see where the problem is? 

I attached the excel file and the code below. Thank you very much again.

data want;

if 5=4 then do;

   set WORK.'RAW DATA'n (keep=date time cycle program_name);

   New_Program_Name = program_name;

end;

set WORK.'RAW DATA'n;

if cycle="PRO" then New_Program_Name = Program_Name;

retain New_Program_Name;

drop Program_Name;

rename New_Program_Name = Program_Name;

run;

 

Super User
Posts: 5,362

Re: How to copy the first cell to the next cells in one column?

Two things would help.  What does the log look like when you run the program?  And what does PROC CONTENTS show about the variables in the data set?

 

It's possible that a very simple fix is in order.  Perhaps Program_name should be replaced by 'Program Name'n if that is the actual name of the variable in your data.  Post the evidence one way or the other. 

Ask a Question
Discussion stats
  • 3 replies
  • 187 views
  • 1 like
  • 2 in conversation