turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- BI
- /
- Enterprise Guide
- /
- Writing Macro in SAS EG

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

06-16-2012 11:32 AM

Hey all,

I have troubles writing my own macro. I have been given a rough guide to try out but i think there's a problem with the logic.

f1 is a column and f2 is another column .

I want to rename them as a column named email.

rename=f2=email);

set WORK.TEXT_14;

set f1 f2;

The macro is named email . To my understanding , that is to get i=1 as the first column to &cnt ( not knowing where is the end column)

data

%do i=**1** to &cnt;

%do i=

&&data&**1**

(keep=&&data&**1**

rename=&&data&**1**=email)

(keep=&&data&

rename=&&data&

%end;

;

set

WORK.TEXT_14;

WORK.TEXT_14;

run;

data

all;

all;

set

%do i=**1** to &cnt;

%do i=

&&data&**1**

%end;

%end;

;

if

email ne '';

email ne '';

run;

%*email*;

My outcome is to get the original dataset of F1 to F92 columns into each table on its own and then append to a column named email.

However, hard coding will be too tiedous.

Thank you

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to cody_q

06-17-2012 04:28 AM

If I understand your problem correct then you don't need macro coding at all. See below:

data have (drop=_;

array F {20} 8.;

do _i=1 to 10;

do _j=1 to dim(F);

f(_j)=ceil(ranuni(0)*10);

end;

output;

end;

run;

data want(keep=email);

set have;

array vars {*} _numeric_;

do _i=1 to dim(vars);

email=vars(_i);

output;

end;

run;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Patrick

06-17-2012 09:26 PM

Hey Patrick , Supposedly i have 10 columns (see below)

FILE A

F1 to F10 are the columns.

F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | F9 | F10 |

There | are | 40 | students | in | the | class | . | They | are |

all | studying | for | Math | and | Science | . | They | have | learnt |

valuable | lessons | from | the | Classes. | The | teachers | are | proud | of |

them | . |

FILE B

Become to F1 as the only column with many rows.

F1 |

There |

are |

40 |

students |

in |

the |

class |

. |

They |

are |

all |

studying |

for |

Math |

and |

Science. |

They |

have |

learnt |

valuable |

lessons |

from |

the |

classes. |

The |

teachers |

are |

proud |

of |

them |

. |

The codes which you have written . Converted the dataset of File A to numerics and then File B to just 1 column with many rows. Yes, this is the expected outcome but i am looking for the words and not numeric . Could you help in the codes you have written. FYI, my real dataset has 92 columns with hundreds of rows.

Thank you .

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to cody_q

06-19-2012 05:39 AM

Assuming all your variables are character a simple change to the code will do. Make sure to define a length for email which is as long as the longest of your input character variables.

data have (drop=_;

array F {20} $20.;

do _i=1 to 10;

do _j=1 to dim(F);

f(_j)=cats('ABC',ceil(ranuni(0)*10));

end;

output;

end;

run;

data want(keep=email);

set have;

array vars {*} _character_;

length email $ 20;

do _i=1 to dim(vars);

email=vars(_i);

output;

end;

run;