BookmarkSubscribeRSS Feed
tylin0117
Calcite | Level 5

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

3 REPLIES 3
Astounding
PROC Star

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;

tylin0117
Calcite | Level 5

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;

 

Astounding
PROC Star

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. 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 3 replies
  • 1018 views
  • 1 like
  • 2 in conversation