Solved

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

Posted on 2013-05-21
5
705 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
ID: 39184265
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
ID: 39185200
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
ID: 39185666
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
ID: 39185910
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
ID: 39197455
The best possible answer was found while testing the code.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

838 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