DATA Step, Macro, Functions and more

How to insert a tag before each record when exporting the table to a comma delimited file?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 16
Accepted Solution

How to insert a tag before each record when exporting the table to a comma delimited file?

Hi Folks,

 

I am struggling here to insert a header tag in the text format of the table. I have a table with the following column:

provider_number drug_name member_first_name member_last_name member_dob product_name date_filled drug_manufacturer prescriber_first_name prescriber_last_name.

 

Problem Explanation:

Provider_Number    Member_first_Name

1                                ABC

1                                LMN

2                                QPR

3                                XYZ

 

What I am trying to accomplish here is make a comma delimited file out of this table with a header right before each Provider/Member pair.

For example:

I want something like this

<Provider>,1

<Member_list>

<Member>, abc {rest of the columns}

<Member>, lmn {rest of the columns}

<Provider>,2

<Member_list>

<Member>,qpr

<Provider>,3 {rest of the columns}

<Member_list>

<Member>,xyz {rest of the columns}

 

My current working code looks like this

data _null_;
	file "<file location>" dlm = ',' dsd;
	set providers_Page2;
	put provider_number drug_name member_first_name member_last_name member_dob product_name date_filled drug_manufacturer prescriber_first_name prescriber_last_name;
run;

Can someone help me with coding the header tags in the text file?

 

Thanks in advance.


Accepted Solutions
Solution
‎08-22-2017 04:59 PM
Trusted Advisor
Posts: 1,831

Re: How to insert a tag before each record when exporting the table to a comma delimited file?

Posted in reply to Abhi_Garg

Try next, not tested, code:

data _null_;
	file "<file location>" dlm = ',' dsd;
	set providers_Page2;
        by provider_number ;
        if first.provider_number then 
        put "<provider>,"  provider_number / "<Member_list>" ;
        put  "<Member>," drug_name member_first_name 
               member_last_name member_dob product_name 
               date_filled drug_manufacturer prescriber_first_name 
               prescriber_last_name;
run;

View solution in original post


All Replies
Solution
‎08-22-2017 04:59 PM
Trusted Advisor
Posts: 1,831

Re: How to insert a tag before each record when exporting the table to a comma delimited file?

Posted in reply to Abhi_Garg

Try next, not tested, code:

data _null_;
	file "<file location>" dlm = ',' dsd;
	set providers_Page2;
        by provider_number ;
        if first.provider_number then 
        put "<provider>,"  provider_number / "<Member_list>" ;
        put  "<Member>," drug_name member_first_name 
               member_last_name member_dob product_name 
               date_filled drug_manufacturer prescriber_first_name 
               prescriber_last_name;
run;
Occasional Contributor
Posts: 16

Re: How to insert a tag before each record when exporting the table to a comma delimited file?

Thank you so much. It works beautifully. 

 

Abhi.

PROC Star
Posts: 1,288

Re: How to insert a tag before each record when exporting the table to a comma delimited file?

Posted in reply to Abhi_Garg

SAS is GREAT for stuff like this!

 

Make sure your input table is sorted by "provider_number".

 

Tom

 

data _null_;
file "C:\directory\file.csv" dlm = ',' dsd;
set providers_Page2;
by provider_number;
if first.provider_number
then put "<Provider>," provider_number / 
"<Member_list>" /
"<Member>," member_first_name member_last_name member_dob product_name date_filled drug_manufacturer prescriber_first_name prescriber_last_name;
else put "<Member>," member_first_name member_last_name member_dob product_name date_filled drug_manufacturer prescriber_first_name prescriber_last_name;
run;
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 117 views
  • 2 likes
  • 3 in conversation