SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
mikegia5
Obsidian | Level 7

Hi,

I'm a long time SAS user (since 1997) but this is my first time using this forum and submitting a request for an enhancement! 

I would like to take a 32 bit IPV4 or 128 bit IPV6 binary IP address and convert to text as dotted notation.  For example, an IPV4 is stored in binary as 4 bytes as x'0a0b0c01' and the text is up to 15 bytes  "010.011.012.001".   While I don't have a requirement right now to go the other way, that may be useful as well (i.e., convert a char(15) field from 10.11.12.1 back into a 4 byte binary).

 

The equivalent functions in unix are inet_ntop (numeric to presentation) and inet_pton (presentation to numeric). 

 

My goal right now is to read in a binary number and display it as dotted notation.  I can work out the SAS code to do this myself, but I really think a function or informat/format would be useful.  For example:

 

input @1 ipv4addr  pib4.

put @1 ipv4addr $ipv4.;

 

The length would be implied to be either char15 if IPV4 or char35 if IPV6.

 

A function would work too - whichever makes sense.

 

Thank you,

Mike Giaquinto

Principal Engineer

Wells Fargo

 

 

 

 

 

2 REPLIES 2
PGStats
Opal | Level 21

You can write your own function or function-based format with proc FCMP and then use it just like any SAS function or SAS format in data steps and SQL.

PG
ChrisHemedinger
Community Manager

Here's an example that might help:

 

Using SAS to convert IP addresses into numerical IP values

 

Chris

Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 5011 views
  • 0 likes
  • 3 in conversation