Hello Experts,
Please what is the best way to insert a column name row into a SAS dataset. It is a part of a larger file that was split into smaller parts for ease of transfer (I don't want to merge the files). See sample below i.e name the columns in file2
HAVE | WANT | |||||||||
FILE1 | FILE1 | |||||||||
ID | date | Brand Code | Total transaction | Value($) | ID | date | Brand Code | Total transaction | Value($) | |
00303 | 1/1/2020 | 11566 | 1234 | 5000 | 00303 | 1/1/2020 | 11566 | 1234 | 5000 | |
05221 | 1/1/2020 | 38220 | 770 | 2000 | 05221 | 1/1/2020 | 38220 | 770 | 2000 | |
44990 | 1/1/2020 | 76489 | 3567 | 7300 | 44990 | 1/1/2020 | 76489 | 3567 | 7300 | |
FILE2 | FILE2 | |||||||||
07773 | 1/11/2020 | 35139 | 2345 | 3350 | ID | date | Brand Code | Total transaction | Value($) | |
22222 | 1/11/2020 | 60275 | 167 | 470 | 07773 | 1/11/2020 | 35139 | 2345 | 3350 | |
10050 | 1/11/2020 | 24677 | 200 | 500 | 22222 | 1/11/2020 | 60275 | 167 | 470 | |
10050 | 1/11/2020 | 24677 | 200 | 500 |
Thank you,
I'm afraid your data doesn't make sense to me.
In FILE2, the HAVE data set has no variable names, which is impossible, all SAS data sets have variable names. Please explain.
The file was split into smaller csv files. When imported into SAS, the first observation is interpreted as variable names.
The files were sent by someone else. I've fixed it. I unchecked the box 'first row of range contains field names'
@PaigeMiller You are right, if the 'first row of range contains field names' box is unchecked, the variables are automatically named F1,F2..........
I am very confused about splitting a file to "transfer" it but not wanting a single file. If the sole purpose of the two files is to append them back together then read them correctly to begin with. You can read multiple files with a single data step. Sort of an example:
filename toread ("c:\path\file1.csv" "c:\path\file2.csv" ); data want; infile toread dlm=',' dsd firstobs=2; informat id $6. date mmddyy10. brand $6. code $5. total value best12.; format date mmddyy10.; informat id date brand code total value ; run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.