SASのユーザ間にてより有益な情報交換・意見交換が行えます

ハッシュテーブルのテーブル名とキーに、特殊文字を含めたSAS名を指定するには?

Reply
New Contributor
Posts: 3

ハッシュテーブルのテーブル名とキーに、特殊文字を含めたSAS名を指定するには?

お世話になっております。

 

SASプログラム内で、ハッシュテーブルを使用する際の方法について質問です。

 

下記のようなハッシュテーブルマクロを用いる際、SAS名やテーブル名に

「TABLENAME('%')」や「COLNAME('+')」といった特殊文字を含める場合、

どのように指定すればよろしいでしょうか?

 

============================

declare hash hwork(dataset: 'TABLENAME' );
  hwork.definekey('COLNAME');
  hwork.definedata('COLNAME');
  hwork.definedone();

============================

 

何卒よろしくお願いいたします。

Trusted Advisor
Posts: 1,392

Re: ハッシュテーブルのテーブル名とキーに、特殊文字を含めたSAS名を指定するには?

Posted in reply to NAO_JUL_13

You might find this tip sheet with examples helpful https://support.sas.com/rnd/base/datastep/dot/hash-tip-sheet.pdf

 

Kind Regards,

Michelle

New Contributor
Posts: 3

Re: ハッシュテーブルのテーブル名とキーに、特殊文字を含めたSAS名を指定するには?

[ Edited ]
Posted in reply to MichelleHomes

Hello, Michelle.

Thanks for your reply,  but  unfortunately that can not solve my question.

 

For example, I attached sample program and log-file, could you check them?

 

In this case, 1st data step has made the dataset "name('%')" correctly.

But the next data step has been failed at L.15 and L.16 .

 

** I tried to use %bquote and %superq  functions, but they confused me ...

 

I really hope your kindest helps.

regards.

Attachment
Super User
Posts: 9,923

Re: ハッシュテーブルのテーブル名とキーに、特殊文字を含めたSAS名を指定するには?

Posted in reply to NAO_JUL_13

You can avoid all that pain in a very simple way by using standard SAS names (letters, digits, underlines) and avoiding the 'some crazy stuff'n construct. Put fancy descriptions and characters in labels, where they belong. This will make your future SAS life much easier.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Trusted Advisor
Posts: 1,392

Re: ハッシュテーブルのテーブル名とキーに、特殊文字を含めたSAS名を指定するには?

Posted in reply to NAO_JUL_13

Hi,

 

As Kurt mentions it might be best to avoid using the special characters such as % in your variable names. Particularly as these are special tokens that SAS parses at compile time unless they are escaped appropriately. I'm not sure whether they can be escaped in the hash object definitions. There seems to be some rules to be aware of when working with hash objects and that % is a special character - see the last point at http://support.sas.com/documentation/cdl/en/lecompobjref/63327/HTML/default/viewer.htm#n1f2an4fc14u4...

 

FYI, one of my favourite SAS documentation sections on how SAS processes a program and special tokens which might be helpful is http://support.sas.com/documentation/cdl/en/mcrolref/62978/HTML/default/viewer.htm#p1lpbl12k9hhkxn1m...

 

Kind Regards,

Michelle

New Contributor
Posts: 3

Re: ハッシュテーブルのテーブル名とキーに、特殊文字を含めたSAS名を指定するには?

Posted in reply to MichelleHomes

Fine, and thanks a lot for you helps.

 

We would like to guide using simple SAS names for our users.

 

Thank you for your kindest helps, regards.

Trusted Advisor
Posts: 1,392

Re: ハッシュテーブルのテーブル名とキーに、特殊文字を含めたSAS名を指定するには?

Posted in reply to NAO_JUL_13

どういたしまして

 

Kind Regards,

Michelle

Ask a Question
Discussion stats
  • 6 replies
  • 490 views
  • 7 likes
  • 3 in conversation