Solved

How to output SAS dataset with variables without ASCII special characters or numbers?

Posted on 2013-05-21
5
678 Views
Last Modified: 2013-05-26
I am trying to output SAS listing of variable "name" without ASCII special characters or numbers?

Below code is where variable "name" contains special characters and numbers. I just also would like to output datasets "data9" and "data10" from dataset "combined" without special characters or numbers.  

proc sql;
    create  table data5 as
    select unique
          name, Var4,
          Var5
    from combined
   where (anyPunct(name) > 0);
 
    create  table data6 as
    select unique
          name, Var4,
          Var5
    from combined
where (anyPunct(name) > 0);
quit;

proc sql;
    create  table data7 as
    select unique
          name, Var4,
          Var5
    from combined
   where (anyDigit(name) > 0);
 
    create  table data8 as
    select unique
          name, Var4,
          Var5
    from combined
where (anyDigit(name) > 0);
quit;

Open in new window

0
Comment
Question by:labradorchik
  • 4
5 Comments
 

Author Comment

by:labradorchik
Comment Utility
I already tried below code but I had many errors and datasets "data9" and "data10" were not created.  

proc sql;
    create  table data9 as
    select unique
          name, Var4,
          Var5
    from combined
   where ((anyPunct(name) = 0) and (anyDigit(name) = 0));
 
    create  table data10 as
    select unique
          name, Var4,
          Var5
    from combined
where ((anyPunct(name) = 0) and (anyDigit(name) = 0));
quit;

Open in new window

0
 
LVL 11

Assisted Solution

by:theartfuldazzler
theartfuldazzler earned 500 total points
Comment Utility
Hi

Try using the compress function :

Name2 = compress(name,, "ck") ;

If I remember correctly, the "ck" will Keep Characters only and drop all numbers and special characters.
0
 

Author Comment

by:labradorchik
Comment Utility
Below code works and outputs variable "name" without any special characters or numbers but I also would like to create another filter:

if Var5  > 5  & < 20 then output to data9 and data10
How may I incorporate this to my already existing "where" statements

proc sql;
    create  table data9 as
    select unique
          name, Var4,
          Var5
    from combined
   where (anyPunct(name) = 0) & (anyDigit(name) = 0);
 
    create  table data10 as
    select unique
          name, Var4,
          Var5
    from combined
where (anyPunct(name) = 0) & (anyDigit(name) = 0);
quit;

Open in new window


I tried below code but it still does not recognize Var5  > 5  & < 20, although, surprisingly no errors. Any comments or suggestions?

proc sql;
    create  table data9 as
    select unique
          name, Var4,
          Var5
    from combined
   where ((anyPunct(name) = 0) & (anyDigit(name) = 0)) & 
   where ((Var5 > 5 | Var5 < 20));
 
    create  table data10 as
    select unique
          name, Var4,
          Var5
    from combined
where (anyPunct(name) = 0) & (anyDigit(name) = 0) &
where ((Var5 > 5 | Var5 < 20));
quit;

Open in new window

0
 

Accepted Solution

by:
labradorchik earned 0 total points
Comment Utility
theartfuldazzler, thank you very much for your comments!

Your example worked partially but below code worked perfectly:

where (anyPunct(name) = 0) and (anyDigit(name) = 0) and Var5 > 5 and Var5 < 20;

Open in new window

0
 

Author Closing Comment

by:labradorchik
Comment Utility
The best possible answer was found while testing the code.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Creating and Managing Databases with phpMyAdmin in cPanel.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now