DATA Step, Macro, Functions and more

how to create a diffetent dataset from one dataset

Reply
Contributor
Posts: 45

how to create a diffetent dataset from one dataset

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
Frequent Contributor
Posts: 82

Re: how to create a diffetent dataset from one dataset

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?
Super Contributor
Super Contributor
Posts: 365

Re: how to create a diffetent dataset from one dataset

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
Super User
Posts: 10,046

Re: how to create a diffetent dataset from one dataset

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
Ask a Question
Discussion stats
  • 3 replies
  • 148 views
  • 0 likes
  • 4 in conversation