BookmarkSubscribeRSS Feed
shahm
Fluorite | Level 6

hello,

 

I have a column of data in a dataset which is attached here. 

the violation column has TDGA and TDGR. First I need to be able to separate the TDGA from the TDGR and then extract only the number to the left. 

 

For instance, if it is TDGR 6.1, I need only 6 (the digit to the left of the .)

 

Thanks,

Maitri

 

2 REPLIES 2
PaigeMiller
Diamond | Level 26

First, many of use will not download Excel (or other Microsoft Office) files as they are a security risk. So I can't see your data. The proper way to provide data is: https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/

 

Next, I don't see any particular need for a macro or macro variable here, you can do this in a DATA step without a macro and without a macro variable, using the SUBSTR function or the ANYDIGIT function. So I suggest you try that (or explain why you think you need a macro or a macro variable).

--
Paige Miller
Kurt_Bremser
Super User
data _null_;
violation = "TDGR 6.1";
want_var = scan(scan(violation,2," "),1,".");
put want_var=;
run;

No macro needed.

Macros are for dynamic code, which is not the case here.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 2 replies
  • 419 views
  • 0 likes
  • 3 in conversation