BookmarkSubscribeRSS Feed
arpit
Calcite | Level 5
I have a data set Filename having following contentent

name
A
AA
B
BB
C
CC
D
DD

Each recods of dataset filename has create a individul file which content is like

A
a S E
b S E
c S E

AA

aa S E
aa S E
BB S E

so on

I want to create each file have different data set

Kindly help me
3 REPLIES 3
ieva
Pyrite | Level 9
Can't really understand what data you have and what you need to do with them.
You have one file with just names of other files and all those other files? What do you need to get?
SPR
Quartz | Level 8 SPR
Quartz | Level 8
Hello Arpit,

This is solution. I am not sure that I understood your intentions. If you have more letters involved A, B, C, D, E, ... etc. then the program have to be converted into a macro. First try to use this:
[pre]
data i;
input name $;
datalines;
A
AA
B
BB
C
CC
D
DD
run;
data a aa b bb c cc d dd;
set i;
S="S";
E="E";
if SUBSTR(name,1,2) = "A" then output a;
else if SUBSTR(name,1,2) = "AA" then output aa;
else if SUBSTR(name,1,2) = "B" then output b;
else if SUBSTR(name,1,2) = "BB" then output bb;
else if SUBSTR(name,1,2) = "C" then output c;
else if SUBSTR(name,1,2) = "CC" then output cc;
else if SUBSTR(name,1,2) = "D" then output d;
else if SUBSTR(name,1,2) = "DD" then output dd;
run;
[/pre]
Sincerely,
SPR
Ksharp
Super User
Sigh.
If you search support.sas.com by yourself ,you will find some example.
I post some exampl code I wrote before.You can refer to it.

[pre]
%let subdir=D:\sasdata\temp\;
data filename;
input filename : $100.;
cards;
A.csv
AA.csv
;
run;

data new;
set filename end=last;
filename=cats("&subdir",filename);
call symputx(cats('path',_n_),filename);
call symputx(cats('dsn',_n_),scan(scan(filename,5,'\'),1,'.'));
if last then call symputx('nobs',_n_);
run;
%put _user_;

%macro import;
%do i=1 %to &nobs;

data WORK.&&dsn&i; ;
%let _EFIERR_ = 0; /* set the ERROR detection macro variable */
infile "&&path&i" delimiter = ',' MISSOVER DSD lrecl=32767 firstobs=2 ;
informat VAR1 best32. ;
informat VAR2 $30. ;
informat VAR3 comma30. ;
informat VAR4 comma30.;
informat VAR5 comma30.;
informat VAR6 comma30.;
informat VAR7 comma30.;
informat VAR8 comma30.;
informat VAR9 best12.;
format VAR1 best12. ;
format VAR2 $30. ;
format VAR3 best32.2 ;
format VAR4 best32.2;
format VAR5 best32.2;
format VAR6 best32.2;
format VAR7 best32.2;
format VAR8 best32.2;
format VAR9 best12. ;
input
VAR1
VAR2
VAR3
VAR4
VAR5
VAR6
VAR7
VAR8
VAR9
;

if _ERROR_ then call symputx('_EFIERR_',1); /* set ERROR detection macro variable */
run;
%end;
%mend import;

%import



[/pre]




Ksharp

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 716 views
  • 0 likes
  • 4 in conversation