BookmarkSubscribeRSS Feed
Erwinb
Calcite | Level 5

Hello,

 

I have a table that I imported from excel into EG. This table is a description of my metadata.

It contains the tablenames/fieldnames but also their 'readable' descriptions of the tables/fields.

 

Is there an easy to query my data to this metadata-table and automatically convert my columnnames to the descriptions?

 

I'm finding it difficult to describe my problem so I do hope i'm making any sense.

I have attached some screenshots.


table description.jpgtable.jpg
4 REPLIES 4
Kurt_Bremser
Super User

I would strongly advise against using the descriptions as column names, as they are not valid Base SAS names (alphabetic characters, numbers and underlines, no special characters and blanks allowed). While this is possible, it then constantly forces you to use the 'some interesting name'n construct when accessing columns.

Instead, you should set the column labels to the descriptions, as SAS output procedures can usually be directed to show the labels instead of the names.

 

So, once you have your description table in SAS, you could do the following:

 

data _null_;
set description_table end=done;
length execute_str $ 2000;
execute_str = catx(' ',trim(execute_str),trim(fieldname)!!'="'!!trim(description)!!'"');
if done then call symput('label_str',trim(execute_str));
run;

Now you can use &label_str in a label statement.

Ksharp
Super User

I see the variable name in metadata file is not exactly matched the name in sas table .

Is there any rule to map them . and Better post some sample data to enable us to test .

RW9
Diamond | Level 26 RW9
Diamond | Level 26

One other option to the two answers provided above, is to have a normalised dataset, with the columns as parameters.  This is a common format in databases (and I am suprised to see a DB2 file with so many columns, doesn't seem like a good structure).  So if you have a file like this:

VCDR_NR  VEST_KD   AFBO_NR...

...

 

What your output dataset would look like is this:

PARAM_CODE         RESULT

VCDR_NR                ...

VEST_KD                 ...

AFBO_NR                ...

...

 

Then it should be a relatively simple task to merge your metadata on to get labels for each param:

PARAM_CODE         RESULT            PARAM

VCDR_NR                ...                     Aan Vestiging

VEST_KD                 ...                     ...

AFBO_NR                ...                     ...

 

You will find this structure can be easier to work with, for instance, if your doing calculations across columns, you have arrays, but you need to know and supply variable names etc.  If you were to stick with the transposed approach - wide - as you have now, I would recommend, not labelling column names as data, but use a generic term, say VAR1-VARx for instance.  Names of columns are to make programming easier, labels of columns are there to provide information.  Make your programming far simpler by following one of the above approaches.

...

ballardw
Super User

Somewhat of a kludge, but I have been known to use a spreadsheet with column information and use that with spreadsheet functions to create a column of LABEL statements to apply to variables. Using a full description in a label makes a lot of sense as you can have more characters and characters that are not acceptable in variable names.

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
  • 4 replies
  • 1503 views
  • 0 likes
  • 5 in conversation