BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
evaleah
Obsidian | Level 7

I am making an API GET call that returns a field I need in the headers. I am able to get the headers into a file using headerout. How do I pull a specific header value into a variable? Here is what I part of the output from headerout.

Server: Microsoft-IIS/10.0
X-AspNetMvc-Version: 3.0
X-MWS-CV-Last-Updated: 2020-12-07T21:54:45
X-AspNet-Version: 4.0.30319

I need to retrieve just X-MWS-CV-Last-Updated. Is there a way to do that short of text parsing the entire thing?

1 ACCEPTED SOLUTION

Accepted Solutions
RichardDeVen
Barite | Level 11

There is no built-in reader for parsing header files.  You can perform simple text processing as follows to get either name/value data set, or single row table after transposing.

 

Example:

filename header temp;

* simulate header returned from API GET call;
data _null_;
  file header; input; put _infile_; datalines;
Server: Microsoft-IIS/10.0
X-AspNetMvc-Version: 3.0
X-MWS-CV-Last-Updated: 2020-12-07T21:54:45
X-AspNet-Version: 4.0.30319
;

data header_items;
  length name value $200;

  infile header;
  input;

  _cpos = index(_infile_,':');

  name  = substr(_infile_,1,_cpos-1);
  value = substr(_infile_,_cpos+1);
run;

proc transpose data=header_items out=header_vars(drop=_name_);
  id name;
  var value;
run;

Name Value pairs

RichardADeVenezia_0-1607462493826.png

 

Header attribute name as column name (after transpose)

RichardADeVenezia_1-1607462583550.png

 

View solution in original post

1 REPLY 1
RichardDeVen
Barite | Level 11

There is no built-in reader for parsing header files.  You can perform simple text processing as follows to get either name/value data set, or single row table after transposing.

 

Example:

filename header temp;

* simulate header returned from API GET call;
data _null_;
  file header; input; put _infile_; datalines;
Server: Microsoft-IIS/10.0
X-AspNetMvc-Version: 3.0
X-MWS-CV-Last-Updated: 2020-12-07T21:54:45
X-AspNet-Version: 4.0.30319
;

data header_items;
  length name value $200;

  infile header;
  input;

  _cpos = index(_infile_,':');

  name  = substr(_infile_,1,_cpos-1);
  value = substr(_infile_,_cpos+1);
run;

proc transpose data=header_items out=header_vars(drop=_name_);
  id name;
  var value;
run;

Name Value pairs

RichardADeVenezia_0-1607462493826.png

 

Header attribute name as column name (after transpose)

RichardADeVenezia_1-1607462583550.png

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 1 reply
  • 1242 views
  • 0 likes
  • 2 in conversation