Assign titles for the fields, while writing to output dataset.

Reply
Contributor
Posts: 20

Assign titles for the fields, while writing to output dataset.

Hi,

I am reading few values from a input dataset, using SAS in mainframes.

And while writing to the output dataset, I need to add titles/header/labels(not sure what we is the exact syntax in sas) for those fields.

For example:

Input file layout:

LA  ,80002,1942,1040

LA  ,80002,1842,1940

LA  ,80004,1713,1510

output file should be as follows: File should have first record as description/title/label for the upcoming records: Kinda of title for all those fields

AREA, LOC , CC ,DEPT

LA  ,80002,1942,1040

LA  ,80002,1842,1940

LA  ,80004,1713,1510

I cant try proc print, because I am writing all records to a output dataset and not in sas log.

Also if i use

proc print data=infile1 label;

label area='AREA1';

run;

I am getting spaces between all those Fields.

Please help.

Contributor
Posts: 74

Re: Assign titles for the fields, while writing to output dataset.

Hi, this only works if all the variables are defined as character.

 

data test1;
length AREA LOC CC DEPT $20;
input area loc cc dept;
datalines;
LA 80002 1942 1040
LA 80002 1842 1940
LA 80004 1713 1510
run;

 

proc contents data = test1 out = cont (keep = name) ; run;


proc transpose data = cont out = vars (drop = _name_ _label_);
id name;
var name;
run;

 

data test2;
set vars test1;
run;

 

 

Super User
Super User
Posts: 6,365

Re: Assign titles for the fields, while writing to output dataset.

Looks like you are just writng a CSV file.  You can try using PROC EXPORT.  Or you can just do it with a data step.

https://communities.sas.com/t5/General-SAS-Programming/Exporting-CSV-File-Using-dsd-option-and-Getti...

 

Ask a Question
Discussion stats
  • 2 replies
  • 156 views
  • 0 likes
  • 3 in conversation